Background

In Azure DevOps there are kind of two ways of setting up pipelines (previously also called builds). One can use the classic editor or the yaml approach. The classic editor is more visual where tasks can be added and modified. A typical setup can look something like this (non dotnet core):

azure-devops-classic-1

By clicking in the right top corner "View YAML" one can see the content of this setup in a yaml format. So basically this "classic" setup is also yaml based behind the scenes.

Instead of using the classical way, one can use yaml all the way. By this I mean that the yaml file will be part of the source checked in. By using one of the YAML variants below a pretty default azure-pipelines.yml is generated:

azure-devops-yaml-wizzard

In most of my projects the auto generated yaml file is not sufficent. I usually need more tasks where gitversion is one of them. My azure-pipelines.yml often looks like this one. Behind the scenes I'm also using GitFlow

trigger:
- develop
- release/*
- feature/*
- bugfix/*
- hotfix/*
 -refs/tags/*

pool:
  name: Default

variables:
  buildConfiguration: 'Release'

steps:
- task: [email protected]
  displayName: 'GitVersion'
  inputs:
    updateAssemblyInfo: true
    preferBundledVersion: false

- script: echo %Action%%BuildVersion%
  displayName: 'Set build version'
  env:
    Action: '##vso[build.updatebuildnumber]'
    BuildVersion: $(GitVersion.SemVer)

- task: [email protected]
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

- task: [email protected]
  displayName: 'dotnet build $(buildConfiguration)'
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: [email protected]
  displayName: 'dotnet test $(buildConfiguration)'
  inputs:
    command: 'test'
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: [email protected]
  displayName: 'dotnet publish $(buildConfiguration)'
  inputs:
    command: 'publish'
    publishWebProjects: false
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    zipAfterPublish: True

- task: [email protected]
  inputs:
    Contents: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    ArtifactType: Container

A successful build that is nicely versioned looks like the one below.

azure-pipeline-successfull

One small note about the pool agent used. The Default one is Windows based build agent, and that is because using an Ubuntu Hosted agent results in System.BadImageFormatException: Method has no body. A related issue can also be found on github

Resources