0

On Azure Devops I want to run ".ci/build.yml" pipeline which builds images in "python/version/flavor" folders.

For each version there is a dockerfile and a version.yml which contains my variables (tags in this case). I want all of them to use the same set of files as build context. Files are in the root folder (project-root).

How do I accomplish this in the best way possible?

Folder structure:

project-root/
├── .ci/
│   └── build.yml
│
├── README.md
├── certs.crt
├── config.json
│
└── python/
    ├── 3.10/
    │   └── bookworm/
    │       ├── Dockerfile
    │       └── version.yml
    │
    ├── 3.11/
    │   └── bookworm/
    │       ├── Dockerfile
    │       └── version.yml
    │
    └── 3.12/
        └── bookworm/
            ├── Dockerfile
            └── version.yml

version.yml example:

variables:
  TAG1: python-3.10-bookworm
  TAG2: python-3.10-slim-bookworm

Right now, I am like 95% way there. I have this:

trigger: none

parameters:
  - name: imageList
    type: object
    default: ["3.10/bookworm",
              "3.11/bookworm",
              "3.12/bookworm",           
              ]

stages:
  - stage: build
    pool: MyLinuxPool
    jobs:
      - ${{ each image in parameters.imageList }}:
        - job: image_${{ replace(replace(replace(image, '-', '_'), '.', '_'), '/', '_') }}
          variables:
            - template: 'python/${{ image }}/version.yml' < PROBLEM IS HERE
            - name: dockerfile
              value: 'python/${{ image }}/Dockerfile' < AND HERE

          steps:
            - task: Docker@2
              displayName: Login to ACR
              inputs:
                containerRegistry: SOME-ACR
                command: login

            - task: Docker@2
              displayName: Build & Push image
              inputs:
                command: buildAndPush
                repository: foo/bar
                dockerfile: $(dockerfile)
                buildContext: '.'
                arguments: '--no-cache'
                tags: |
                  ${{ variables.TAG1 }}
                  ${{ variables.TAG2 }}

I know that this works with a simpler folder structure. The problem is when I run it right now, I get /.ci/build.yml: File /.ci/python/3.10/bookworm/version.yml not found in repository

It starts checking path from .ci folder and not root. How do I change that? I tried experimenting with https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#agent-variables-devops-services but nothings seems to work.

1 Answer 1

0

Templates are either absolute or relative to the file that does the including.

Your pipeline resides in the /.ci folder, so all file references will be relative to that.

In your scenario, you simply need to reference the template using an absolute path:

Change:

 - template: 'python/${{ image }}/version.yml'

to:

 - template: '/python/${{ image }}/version.yml'
Sign up to request clarification or add additional context in comments.

1 Comment

Such a simple fix, thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.