I'm trying to have a deployment pipeline that deploys 3 Azure WebJobs (continous) that are all part of the same solution at once. I can do this in Visual Studio by right click deploy and ensure I'm not clearing existing files.
In Azure Pipelines I have the following script that works successfully for a single WebJob Deployment.
However, if I duplicate it and create an new pipeline for my second WebJob, it will replace the existing WebJob, only leaving 1 running.
What do I modify in the below pipeline for it build/deploy all 3 WebJobs?
trigger: none
pool:
vmImage: ubuntu-latest
# Modify these variables
variables:
webJobName: 'My.WebJob.App'
azureAppServiceName: 'my-webjobs'
azureSPNName: 'MyRGConnection' #get it from your AzureDevOps portal
buildConfiguration: 'Release'
dotNetFramework: 'net6.0'
dotNetVersion: '6.0.x'
targetRuntime: 'win-x86'
# Build the app for .NET 6 framework https://www.tiffanychen.dev/Azure-WebJob-Deployments-YAML/
steps:
- task: UseDotNet@2
inputs:
version: $(dotNetVersion)
includePreviewVersions: true
displayName: 'Build .NET 6 Application'
- task: DotNetCoreCLI@2
inputs:
command: publish
publishWebProjects: false
arguments: '--configuration $(BuildConfiguration) --framework $(dotNetFramework) --runtime $(targetRuntime) --self-contained --output $(Build.ArtifactStagingDirectory)/WebJob/App_Data/jobs/continuous/$(webJobName)'
zipAfterPublish: false
modifyOutputPath: false
projects: '$(webJobName)/$(webJobName).csproj'
# Package the file and uploads them as an artifact of the build
- task: PowerShell@2
displayName: Generate run.cmd For WebJob
inputs:
targetType: 'inline'
script: '"dotnet $(WebJobName).dll" | Out-File run.cmd -Encoding ASCII; $LASTEXITCODE'
pwsh: true
workingDirectory: '$(Build.ArtifactStagingDirectory)/WebJob/App_Data/jobs/continuous/$(webJobName)'
- task: ArchiveFiles@2
displayName: Zip Desired Files
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/WebJob/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(webJobName).zip'
replaceExistingArchive: true
- task: PublishPipelineArtifact@1
displayName: Publish All Artifacts
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: 'pipeline'
- task: DownloadPipelineArtifact@2
displayName: 'Download Build Artifact'
inputs:
path: '$(System.ArtifactsDirectory)'
- task: AzureWebApp@1
inputs:
azureSubscription: $(azureSPNName) #this is the name of the SPN
appType: 'webApp'
appName: $(azureAppServiceName) #App Service's unique name
package: '$(System.ArtifactsDirectory)/$(webJobName).zip'
deploymentMethod: 'zipDeploy'
Variables give you a convenient way to get key bits of data into various parts of the pipeline. The issue is due to the hard coded values in the pipeline. As a result whenever we are running the pipeline, always same WebJob gets deployed.
The way to solve this problem is by replacing the hardcoded values by Pipeline variables as shown below.
We need to create pipeline variables and assign the values. Before running the .yml pipeline, variable need to be assigned with desired values for the WebJob.
You can check this Define Variable document for more information.
You can also check this Variable Group for Azure Pipeline document.