Azure Release Pipeline IISVirtualDirectory YAML - azure

I'm having this Release created via Azure and its working perfectly. I have create the pipeline using YAML and i want to put the release in the same file. I'm using the "View YAML" approach for this to copy the YAML template and use it. But somehow its failing with this message:
ERROR ( message:Cannot find APP object with identifier "TEST01/". )
##[error]Process 'appcmd.exe' exited with code '1168'.
I guess im missing some other parameters or i really can't figure out how to use the same approach using YAML.
This is the code:
trigger:
- develop
stages:
- stage:
jobs:
- job: Build
displayName: Agent job 1
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- task: ArchiveFiles#2
displayName: Archive $(System.DefaultWorkingDirectory)
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
- stage:
jobs:
- job: Deploy
displayName: Deploy to IIS Dev
pool:
vmImage: windows-2019
steps:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: iISVirtualDirectory
ParentWebsiteNameForVD: TEST01
VirtualPathForVD: /admin/test
PhysicalPathForVD: '%SystemDrive%\inetpub\_phpapps\test-center'
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: "TEST01"
VirtualApplication: "/admin/test"
TakeAppOfflineFlag: True
XmlVariableSubstitution: True

After some research and testing seams like there is a new approach regarding deployment/releases.
Instead of using "Pipelines > Release" and create a release, if you are using the Yaml approach (defining stages etc.) you need to use it with "Environments". Create the group or environment and use it.
Two steps here are missing, one is the package and the other is env, where should be deployed.
So the solution for the above code is the following:
- stage: 'DeployTest'
displayName: 'DeployTest'
dependsOn: 'Build'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'develop'))
jobs:
- deployment: Test
displayName: Test
environment:
name: 'ENV-TEST-GROUP'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: iISVirtualDirectory
ParentWebsiteNameForVD: TEST01
VirtualPathForVD: /admin/test
PhysicalPathForVD: '%SystemDrive%\inetpub\_phpapps\test-center'
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: "TEST01"
VirtualApplication: "/admin/test"
Package: $(Pipeline.Workspace)\drop\build_test.zip
TakeAppOfflineFlag: True
XmlVariableSubstitution: True

Related

Azure FunctionApp without functions after successful CI/CD over Azure DevOps

I've created an Azure Function App (Linux) running on an App Service Plan Y1 and have my sources in Azure DevOps Git. The functions are written in C# on DOTNET 6.
Below you can see my YAML definitions for the CI and a separated CD pipeline. When I execute the pipeline everything works well (both are green). After the deployment however this is how my Azure Portal looks in the Functions blade:
Using the VS Code Azure Extension and looking into the files of the function app I get:
When I look in the artifact of the CI pipeline everything looks good (explorer view of the downloaded zip):
The bin-folder is populated there.
Some key points:
I have no slots in the function app.
The deployments are visible in the associated App Insights.
My reference point is Microsoft Learn
So is it normal to get the 404 when searching in VS code and did somebody experience something similar or even know the solution?
Sidenote:
I used to deploy my function using VS Code with extensions install. Today I now get a weired error message after the deployment:
CI YAML
pool:
vmImage: 'ubuntu-latest'
trigger: none
variables:
- name: 'Solution'
value: '**/MyProject.sln'
- name: 'ProjectFilter'
value: '**/*.csproj'
- name: 'BuildConfiguration'
value: 'Release'
steps:
- task: UseDotNet#2
displayName: Use DotNet 6
inputs:
version: '6.0.x'
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '$(ProjectFilter)'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(ProjectFilter)'
arguments: '--no-restore --configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: Publish Image Converter
inputs:
command: publish
projects: src/Functions/**/MyProject.csproj
publishWebProjects: false
arguments: '--no-restore --no-build --configuration $(BuildConfiguration) --output $(Build.DefaultWorkingDirectory)/function_publish_output'
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: Archive Image Converter
inputs:
rootFolderOrFile: '$(Build.DefaultWorkingDirectory)/function_publish_output'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/MyProject.zip'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
condition: succeededOrFailed()
CD YAML
variables:
- name: 'vmImageName'
value: 'ubuntu-latest'
- name: 'serviceConnectionName'
value: 'MYCONN'
- name: 'project'
value: 'MYPROJECT'
resources:
pipelines:
- pipeline: ci
source: 'NAMEOFCI'
trigger: true
pool:
vmImage: $(vmImageName)
trigger: none
stages:
- stage: Production
displayName: Production
jobs:
- deployment: Deploy
displayName: 'Deploy'
environment: 'Production'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- download: ci
displayName: 'Download Artifact'
artifact: drop
- task: AzureFunctionApp#1
displayName: 'Deploy Image Converter Function'
inputs:
azureSubscription: '$(serviceConnectionName)'
appType: functionAppLinux
appName: 'fapp-**********-prod'
package: '$(Pipeline.Workspace)/ci/drop/MyProject.zip'
runtimeStack: 'DOTNET|6.0'
Can you check what exactly you see on the file system? You can use console or Advanced tools:

Deploy to AzureDevOps - Error: Failed to get App service 'xxx' application settings

I want to deploy a Static Web App. Build and deploy stages are specified in azure-pipeline. The pipeline fails when it comes to AzureAppServiceSettings#1 task. That is what I got in log:
Got service connection details for Azure App Service:'xxx-dev-app'
Trying to update App Service Application settings. Data: {"testDb":"test"}
##[error]Error: Failed to get App service 'xxx-dev-app' application settings. Error: The Resource 'Microsoft.Web/sites/xxx-dev-app' under resource group 'xxx-dev-rg' was not found.
The task in azure-pipeline is:
- task: AzureAppServiceSettings#1
displayName: Azure App Service Settings
inputs:
azureSubscription: 'ServiceConnectionName'
appName: 'xxx-dev-app'
resourceGroupName: 'xxx-dev-rg'
appSettings: |
[
{
"name": "testDb",
"value": "test",
"slotSetting": false
}
]
DevOps has a Contributor access level both in the app and resource group.
Any suggestions what causes deployment failure?
I added a task for artifact downloading as it was proposed by #Daniel Mann, and it worked:
trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
stages:
- stage: Build
jobs:
- job: Build
displayName: 'Build'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
configuration: 'Release'
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration $(buildConfiguration)
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Test
dependsOn: Build
condition: succeeded()
jobs:
- job: Deploy
displayName: 'Deploy to Test'
steps:
- download: current
artifact: drop
- task: AzureWebApp#1
inputs:
azureSubscription: 'yyy'
appType: 'webApp'
appName: 'xxx'
package: '$(Pipeline.Workspace)/drop/*.zip'

Use powershell script to customize azure devOps pipeline?

I have an azure function app that is running on Azure. I am now trying to configure the application based on a powershell script. This powershell script is being used to create azure resources (Ex: KeyVault, ApplicationInsights...) that will be then used by the function app. I created the powershell script and my question here is how can I add the powershell script in the yaml file which is responsible to deploy the application. The powershell script is located in the repository under the name functionapp.ps1 . The idea here is to run the powershell script once the build is finished so in the deploy stage. What I did so far is the following:
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: 'build'
projects: |
$(workingDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: CmdLine#2
inputs:
script: |
echo '$(System.DefaultWorkingDirectory)'
dir
- task: PowerShell#2
inputs:
targetType: 'filePath'
filePath: $(System.DefaultWorkingDirectory)/functionapp.ps1
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionApp
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
When the stages are being run and it arrives to this task I get the following error:
##[error]Invalid file path 'D:\a\1\s\functionapp.ps1'. A path to a .ps1 file is required.
I tried using the command line task to check the default working directory and I got the following result: D:\a\1\s
I still don't know what I am missing here and why I am getting this error. Can someone please give me a concrete solution to this problem ?
I ended up having the same error. Can someone please tell me what is the issue here ?

How can I set the EnvironmentName for XML transformation during a deployment job?

Alright folks, giving Azure multi-stage-pipelines feature a go and not having much luck getting xml transformations using a deployment job to work.
Update: This is not using the Classic Deploy/Release UI in Azure DevOps
What I've done so far:
remove transformations from the build process. Attempting to build once and deploy everywhere
verified that the web.{stage}.config files are included in the webdeploy package by removing node in csproj
Set up stage with name of 'Development'
pipeline yaml
trigger:
batch: false # If batch set to true, when a pipeline is running, the system waits until the run is completed,
branches:
include:
- staging-devops
paths:
include:
- myProject/*
- API/*
variables:
BuildConfiguration: 'Release'
BuildPlatform: 'Any CPU'
System.Debug: true
stages:
- stage: Build
displayName: 'Build project'
jobs:
- job:
displayName: 'Build and package client'
pool:
vmImage: 'vs2017-win2016'
demands:
- msbuild
- visualstudio
steps:
- task: VSBuild#1
displayName: 'Visual Studio build'
inputs:
solution: 'myProject/myProject.csproj'
vsVersion: '15.0'
msbuildArgs: '/p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: 'AnyCPU'
configuration: 'Release'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(build.artifactstagingdirectory)'
artifactName: 'myProject-web-client'
- job:
displayName: 'Build and package API'
pool:
vmImage: 'vs2017-win2016'
demands:
- msbuild
- visualstudio
steps:
# add caching of nuget packages
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: 'API/myAPI.sln'
- task: VSBuild#1
displayName: 'Visual Studio build'
inputs:
solution: 'API/myAPI.sln'
vsVersion: '15.0'
msbuildArgs: '/p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
# configuration: '$(BuildConfiguration)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(build.artifactstagingdirectory)'
artifactName: 'myProject-api'
- stage: Development
displayName: 'Development'
dependsOn: Build
condition: succeeded('Build') #add check if artifact is available
jobs:
- deployment: DeploymyProjectClient
displayName: 'Deploy web client'
timeoutInMinutes: 30
pool:
vmImage: "windows-latest"
environment:
name: Staging
resourceType: VirtualMachine
tags: web
strategy:
runOnce:
deploy:
steps:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'Deploy web application (myProject)'
inputs:
webSiteName: myProjectDev
package: '$(Pipeline.Workspace)/myProject-web-client/**/*.zip'
removeAdditionalFilesFlag: true
- deployment: Development
displayName: 'Development'
timeoutInMinutes: 30
pool:
vmImage: "windows-latest"
environment:
name: Staging
resourceType: VirtualMachine
tags: web
strategy:
runOnce:
deploy:
steps:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: Development
inputs:
webSiteName: 'WebAPI-Test'
package: '$(Pipeline.Workspace)/myProject-api/**/*.zip'
xmlTransformation: true
I've tried variations of the stage name, displayname, deployment name, etc still can't get the transformation for the Development stage to fire.
I do get the web.config and web.release.config to work but that is it.
2020-05-02T05:26:04.9272125Z ##[debug]adjustedPattern: 'C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\**/*.config'
2020-05-02T05:26:04.9343033Z ##[debug]9 matches
2020-05-02T05:26:04.9345300Z ##[debug]9 final results
2020-05-02T05:26:04.9351908Z ##[debug]Applying XDT Transformation : C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\1\s\API\obj\Debug\Package\PackageTmp\Web.Release.config -> C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\1\s\API\obj\Debug\Package\PackageTmp\Web.config
When reviewing the log file for deployment I do see the following
##[debug]Release.EnvironmentName=undefined
How can I set the stage name properly in order for the transformations to be applied during deployment??
How can I set the EnvironmentName for XML transformation during a deployment job?
This is known issue that has already been reported to product team.
As workaround, you could try to set the variable Release.EnvironmentName on the stage-level and on the job-level:
- stage: Development
displayName: 'Development'
dependsOn: Build
condition: succeeded('Build') #add check if artifact is available
variables:
Release.EnvironmentName: Development
jobs:
Then, the environment-specific config transformation was triggered.
Hope this helps.
Please try $(System.StageName).

Azure Pipeline (YAML) deploys an empty solution to my FunctionApp

I'm building a CI-CD azure pipeline with YAML to deploy an azure function app.
Everything works fine, I can even set some properties for the function app, but my function app remains empty.
I downloaded the zip artifact and it looks just fine.
trigger:
- master
variables:
variables:
buildConfiguration: 'Release'
Parameters.RestoreBuildProjects: '**/TestFunction.csproj'
stages:
- stage: Build
jobs:
- job:
pool:
vmImage: 'vs2017-win2016'
continueOnError: false
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore'
inputs:
command: 'restore'
projects: '$(Parameters.RestoreBuildProjects)'
feedsToUse: 'select'
vstsFeed: '/0856b234-f3a6-4052-b5a6-ed9f6ec9c635'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish Build'
inputs:
command: publish
arguments: '--configuration $(BuildConfiguration)'
projects: '$(Parameters.RestoreBuildProjects)'
publishWebProjects: false
modifyOutputPath: true
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: "Archive Files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
ArtifactName: 'drop'
- stage: Deploy
jobs:
# track deployments on the environment
- deployment:
pool:
vmImage: 'vs2017-win2016'
# creates an environment if it doesn’t exist
environment: 'dev'
strategy:
# default deployment strategy
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Artifacts'
inputs:
buildType: 'current'
downloadType: 'specific'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureFunctionApp#1
displayName: 'Azure Function App Deploy: ngproductionfetcherfuncref'
inputs:
azureSubscription: 'Agder Energi Sandbox (1aa9cf92-9d42-49a6-8d31-876ac2dff562)'
appType: functionApp
appName: myFunctionApp
package: '$(System.ArtifactsDirectory)/**/*.zip'
appSettings: '-name0 value0 -name1 value1'
The pipeline is all green:
Got service connection details for Azure App Service:'myFunctionApp'
Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"} {"WEBSITE_RUN_FROM_ZIP":{"value":""}}
Updated App Service Application settings and Kudu Application settings.
Package deployment using ZIP Deploy initiated.
Successfully deployed web package to App Service.
Updating App Service Application settings. Data: {"name0":"value0","name1":"value1"} undefined
Updated App Service Application settings and Kudu Application settings.

Resources