Use runtime variable for repository name in checkout in Azure Pipelines

Viewed 3784

I have a matrix in a multi-stage pipeline that generates jobs to go and checkout to different git repositories and make commits.

The matrix has the repo name as a value, and I want to reference that during a checkout task. However I keep getting errors due to the variable being evaluated at runtime.

i.e. matrix

matrix:
  repo_foo:
    repo: foo
  repo_bar:
    repo: bar

and I want to do something like

steps:
- checkout: $[ variables['repo'] ]

but those isn't evaluated and throws an error before the pipeline starts. Similarly, using ${{ variables['repo'] }} also fails because it gets evaluated at compile time and thus becomes an empty string.

I've defined the potential repos as resources in the pipeline yaml, as well as attempting to pass the full git path as the variable value.

Is there another way I can do this?

2 Answers

According to the test, variable syntax should not be supported in the checkout step.

If you use variables to refer to the repo in the checkout step, then when you start running the pipeline you will get the following error:

enter image description here

steps:
- checkout: self | none | repository name # self represents the repo where the initial Pipelines YAML file was found

You can refer to this official document .

You could get related resource by calling git clone command per to matrix variable value.

Related