EverythingPython

Azure Devops TIL

TIL about the importance of buildContext in Azure Devops Pipelines for a Docker@2 task. 😵

Kept breaking my head trying to copy files over to an image and it kept saying they weren’t found. Tried a hundred combinations of paths and folder structures.

Finally after some github-repo-hunting and documentation reading (No, LLMs didn’t help) , turned out I was building a dockerfile two levels deeper from my root path and the context was set by default as the path where the Dockerfile was present.

Once I explicitly set the buildContext, everything else fell in place. 😪

Here’s the net snippet for the Docker part of the ADO YAML :

 1  - job: Build
 2    displayName: Build Docker Image
 3    steps:
 4      - task: Docker@2
 5        displayName: Build image and tag
 6        inputs:
 7          command: 'build'
 8          Dockerfile: ./src/intermediate_folder/Dockerfile
 9          buildContext: './src/'
10          arguments: "--no-cache --build-arg <arg1> --build-arg <arg2> --pull -t latest "
11          tags: $(Build.BuildNumber)

Since I had omitted the buildContext, I couldn’t access the files in the src folder. Took me a while to figure this out. 😅


Reference -