Azure DevOps, Docker and Pipelines – An unexpected twist

So as part of the Microservice project i’m creating myself, I thought I’d use Devops Pipelines for the build process. Having never gone in-depth with creating a pipeline, I thought it would be fairly straightforward. Not so!

My first problem that I came across was trying to pull my first branch into my development branch. I got this helpful error:

No hosted parallelism has been purchased or granted

Following the instructions, for a personal account, it turns out I needed to create a self hosted agent to do this.

I turned to docker, because a) i thought it would be simple, and b) because container-ism is something I’d like to get to know more.

so after following the instructions here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops

and here:
https://learn.microsoft.com/en-us/training/modules/host-build-agent/

I was still struggling. My non-working pipeline yaml looked like this:

YAML
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- development

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'


why wasn’t it working? ah, the pool seems incorrect, so after seeing this bit of guidance on Stack Overflow:

I updated my yaml to this:

YAML
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- development

pool:
  name: DockerAgentPool
  demands:
   - agent.name -equals SelfHostedDockerAgent

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

- task: UseDotNet@2
  displayName: 'Use .NET SDK 8.x'
  inputs:
    packageType: sdk
    version: '8.x'

- task: DotNetCoreCLI@2
  displayName: 'Restore project dependencies'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Build the project - Release'
  inputs:
    command: 'build'
    arguments: '--no-restore --configuration Release'
    projects: '**/*.csproj'

but it still wasn’t working. It couldn’t file the csproj file to build. But of course it couldn’t because the csproj was still in the “initial checkin” branch from task 1 which could merge in because it was waiting for the pipeline to work.

In the end I had to comment out the dotnet build task and replace it with a simple echo Hello World task (because the pipeline required a script). This enabled the yaml fixes to go in and got the pipeline working.

I could then merge in the “initial checkin” branch and then finally update the yaml to include the tasks and scripts.

It now, so far, merges my branches in correctly! Woohoo!

On to the next part….


Posted

in

by

Tags: