1

I work in a platform team that builds and supports Azure Pipelines YAML templates and various custom scripting for these pipelines. People in my organisation use these YAML templates like:

resources:
  repositories:
    - repository: templates
      type: git
      name: PROJECT/cicd_stuff
      ref: refs/heads/releases/v0.21
extends:
  template: our_awesome_template.yml@templates
  parameters:
    ...

In order to reliably match the version of our scripts to the version of the YAML templates, we now include an extra build stage in our pipeline templates that checks out the repo templates repo and puts all our scripts in an artifact to be used in that run. Using "release branches" allows us to safely put out and test new features and fixes to our pipelines: Teams can upgrade their pipeline on their own pace, with older version remaining supported for a while.

I'd like to start using Azure Artifacts for our script artifacts, but now I'm wondering "how can I determine which version of my scripts I should be downloading from Azure Artifacts?" The information included in the resources block would work for me, but I can't seem to access that with an expression or with a predefined variable. The only solution I can currently think of is to use the az pipelines cli. Any thoughts?

1 Answer 1

4

You can do:

variables:
  templates.ref: $[ resources.repositories['templates'].ref ]

See Repository Details docs.

2
  • Thanks, I didn't know that. The problem though is that I have to know that exact name that was used to include our repo (templates in this example) in order to access the correct resource's properties. Do you know of an approach that would allow me to access a property in $[ resources.repositories[*] based on the name property? of a repository resource?
    – Walter Vos
    Commented Apr 20, 2021 at 6:44
  • 1
    I don't think there's a way to do it in yaml. You could enforce the resource name by having a step with condition: eq(variables['templates.ref'], '') that would do something like throw "Please name the referenced repostiory as 'template'"
    – qbik
    Commented Apr 20, 2021 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.