The last couple of posts have been dealing with Release managed from the Releases area under Azure Pipelines. This week we are going to take what we were doing in that separate area of Azure DevOps and instead make it part of the YAML that currently builds our application. If you need some background on how the project got to this point check out the following posts.
Getting Started with Azure DevOps
Pipeline Creation in Azure DevOps
Azure DevOps Publish Artifacts for ASP.NET Core
Azure DevOps Pipelines: Multiple Jobs in YAML
Azure DevOps Pipelines: Reusable YAML
Azure DevOps Pipelines: Use YAML Across Repos
Azure DevOps Pipelines: Conditionals in YAML
Azure DevOps Pipelines: Naming and Tagging
Azure DevOps Pipelines: Manual Tagging
Azure DevOps Pipelines: Depends On with Conditionals in YAML
Azure DevOps Pipelines: PowerShell Task
Azure DevOps Releases: Auto Create New Release After Pipeline Build
Azure DevOps Releases: Auto Create Release with Pull Requests
The current setup we have uses a YAML based Azure Pipeline to build a couple of ASP.NET Core web applications. Then on the Release side, we have basically a dummy release that doesn’t actually do anything but served as a demo of how to configure a continuous deployment type release. The following is the current YAML for our Pipeline for reference.
name: $(SourceBranchName)_$(date:yyyyMMdd)$(rev:.r)
resources:
repositories:
- repository: Shared
name: Playground/Shared
type: git
ref: master #branch name
trigger: none
variables:
buildConfiguration: 'Release'
jobs:
- job: WebApp1
displayName: 'Build WebApp1'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'Get-ChildItem -Path Env:\'
- template: buildCoreWebProject.yml@Shared
parameters:
buildConFiguration: $(buildConfiguration)
project: WebApp1.csproj
artifactName: WebApp1
- job: WebApp2
displayName: 'Build WebApp2'
condition: and(succeeded(), eq(variables['BuildWebApp2'], 'true'))
pool:
vmImage: 'ubuntu-latest'
steps:
- template: build.yml
parameters:
buildConFiguration: $(buildConfiguration)
project: WebApp2.csproj
artifactName: WebApp2
- job: DependentJob
displayName: 'Build Dependent Job'
pool:
vmImage: 'ubuntu-latest'
dependsOn:
- WebApp1
- WebApp2
steps:
- template: buildCoreWebProject.yml@Shared
parameters:
buildConFiguration: $(buildConfiguration)
project: WebApp1.csproj
artifactName: WebApp1Again
- job: TagSources
displayName: 'Tag Sources'
pool:
vmImage: 'ubuntu-latest'
dependsOn:
- WebApp1
- WebApp2
- DependentJob
condition: |
and
(
eq(dependencies.WebApp1.result, 'Succeeded'),
in(dependencies.WebApp2.result, 'Succeeded', 'Skipped'),
in(dependencies.DependentJob.result, 'Succeeded', 'Skipped')
)
steps:
- checkout: self
persistCredentials: true
clean: true
fetchDepth: 1
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$env:GIT_REDIRECT_STDERR` = '2>&1'
$tag = "manual_$(Build.BuildNumber)".replace(' ', '_')
git tag $tag
Write-Host "Successfully created tag $tag"
git push --tags
Write-Host "Successfully pushed tag $tag"
failOnStderr: false
#azure-pipelines #azure #azure-devops #devops