Repository for commonly used Azure Pipeline templates.
- Create new feature branch
- Use the branch reference (
ref: refs/heads/branch-name) in pipeline to test out changes in this branch, see below for examples - Do the changes, push, create PR
- Merge to main branch
- Add new version tag (vN+1) if there are breaking changes to exiting template(s) or move version tag (set same tag) to latest commit.
Avoid any breaking changes (interface aka required parameters or changing template file name or location) as much as possible. When adding parameters to templates, add default value, so that pipelines using the template do not fail. Do not rename the template file or move to another directory. This will break the reference from pipelines using the template.
Adding new template file is not breaking change but new feature. As soon as any pipeline starts using the template you risk breaking the pipeline when changing the template interface (name and required parameters).
- You have to find all the usages for the template and change those pipelines, when only few pipelines use it.
- Add new version tag in format of vX (like v1 or v2) where X is integer. Then you can use the specific tag reference and reference new and old version (tag) in pipelines.
Move the tag to new commit (tag the commit with same version) after merging the changes to main branch so that pipelines referencing specific tag version get the changes.
resources:
repositories:
- repository: templates
type: git
name: azure-devops-project-name/azure-pipeline-templates
stages:
- template: stages/set-version.yml@templatespool:
vmImage: 'ubuntu-latest'pool: 'my-agent-pool'
# or
pool:
name: 'my-agent-pool'You cannot use other files, like scripts, from the templates repository. Only the template files are combined with original pipeline and compiled into one yaml.
Use tag reference to anchor against specific tag, so that any breaking changes to templates do not break your pipeline. If you need to change templates and test templates from other branch than main branch then use ´ref´ keyword.
resources:
repositories:
- repository: templates
type: git
name: azure-devops-project-name/azure-pipeline-templates
ref: refs/tags/v1 # Note: Referenc specific tag. For testing you can specify branch name, refs/heads/branch-name.NET Nuget package test, analyze, build and publish to Azure Artifactory.
This template is used to build and publish .NET / .NET Core / .NET Standad Nuget projects.
trigger:
- master
# Set the default agent pool for all stages
pool:
vmImage: 'ubuntu-latest'
resources:
repositories:
- repository: templates
type: git
name: azure-devops-project-name/azure-pipeline-templates
ref: refs/tags/v1
extends:
template: pipelines/pipeline-dotnet-nuget.yml@templates
parameters:
projectName: 'Bondora.Sample.Nuget' # Mandatory, used for project name (projectName.csproj)
parameters:
- name: serviceName
type: string
variables:
- group: 'azure-container-registry'
pool:
vmImage: 'ubuntu-latest'
resources:
repositories:
- repository: templates
type: git
name: azure-devops-project-name/azure-pipeline-templates
ref: refs/tags/v1
stages:
- template: stages/set-version.yml@templates
- template: stages/build-test-analyze-dotnet.yml@templates
parameters:
sonarProjectKey: ${{ parameters.serviceName }}
- template: stages/build-and-push-docker-image.yml@templates
parameters:
dockerImage: ${{ parameters.serviceName }}
- template: stages/add-version-tag.yml
parameters:
dependsOn: Build_Publish
- template: stages/deploy-to-kubernetes-with-helm.yml@templates
parameters:
dependsOn: AddVersionTag
environmentName: Staging
serviceName: ${{ parameters.serviceName }}
- template: stages/deploy-to-kubernetes-with-helm.yml@templates
parameters:
dependsOn: AddVersionTag
environmentName: Production
serviceName: ${{ parameters.serviceName }}- Parameter
serviceNameis required, so that service name can be displayed inside Slack message. - Parameter
infoMessageis optional informational message in Slack message.
stages:
- stage: Deploy_Stage
jobs:
- job: Deploy_Job
steps:
- bash: 'echo success'
- template: jobs/notify-deploy-started-to-slack.yml
parameters:
serviceName: 'MyServiceName'- Parameter
serviceNameis required, so that service name can be displayed inside Slack message. - Parameter
deployJobIdentifieris required. Value is "StageName.JobName", if you use deployments, then add ".Deploy" suffix to the end ("StageName.JobName.Deploy"). - Parameter
dependsOnvalue should be set to deploy Job name. - Parameter
infoMessageis optional informational message in Slack message.
stages:
- stage: Deploy_Stage
jobs:
- job: Deploy_Job
steps:
- bash: 'echo success'
- template: jobs/notify-deploy-finished-to-slack.yml
parameters:
serviceName: 'MyServiceName'
deployJobIdentifier: 'Deploy_Stage.Deploy_Job'
dependsOn: Deploy_JobUse jobs/notify-deploy-started-to-slack.yml and jobs/notify-deploy-finished-to-slack.yml templates for deploy notifications - before and after deploy job.
You can use this template inside the deploy stage before and after deployment job(s) to notify slack before and after deployment.
- Parameter
serviceNameis required, so that service name can be displayed inside Slack message. - Parameter
deployStateallowed values arestartedandended. - When
deployState: startedparameter is specified, then service name, version and first 10 commit messages are shown is Slack message. - When
deployState: endedparameter is specified, then deployment result (succeeded, failed, skipped, canceled) and errors, when present, are shown. - Parameter
deployJobIdentifieris required only ifdeployStateparameter value isended. Value is "StageName.JobName", if you use deployments, then add ".Deploy" suffix to the end ("StageName.JobName.Deploy"). - Parameter
dependsOnvalue should be set as deploy job name whendeployState: endedis specified. - Parameter
infoMessageis optional informational message in Slack message.
- template: ../jobs/notify-deploy-to-slack.yml
parameters:
serviceName: 'My service name'
deployState: startedExample
stages:
- stage: TestNotifySlackJobSuccess
jobs:
- template: jobs/notify-deploy-to-slack.yml
parameters:
serviceName: 'test-notify-slack-job-success-started'
- job: TestNotifySlackJobSuccess_Job
steps:
- checkout: none
- bash: 'echo success'
- template: jobs/notify-deploy-to-slack.yml
parameters:
serviceName: 'test-notify-slack-job-success-ended'
deployState: 'ended'
deployJobIdentifier: 'TestNotifySlackJobSuccess.TestNotifySlackJobSuccess_Job'
dependsOn: TestNotifySlackJobSuccess_Job- template: ../jobs/notify-deploy-to-slack.yml
parameters:
serviceName: 'My service name'
deployJobIdentifier: 'Deploy_Stage.Deploy_Job'
dependsOn: Deploy_Job
deployState: endedExample
stages:
- stage: TestNotifySlackJobFailed
jobs:
- template: jobs/notify-deploy-to-slack.yml
parameters:
serviceName: 'test-notify-slack-job-failed-started'
- job: TestNotifySlackJobFailed_Job
steps:
- checkout: none
- bash: 'exit 1'
- template: jobs/notify-deploy-to-slack.yml
parameters:
serviceName: 'test-notify-slack-job-failed-ended'
deployState: 'ended'
deployJobIdentifier: 'TestNotifySlackJobFailed.TestNotifySlackJobFailed_Job'
dependsOn: TestNotifySlackJobFailed_Job