2
votes

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
I don't see what using Azure Artifacts is going to get you here. What advantages do you perceive over the method you're using now? I've used the approach you use now with success a bunch of times; the only difference is that we used tags instead of branches.Daniel Mann
We've started to package these deployment scripts as functions in a PowerShell module, and we're starting to use Python as well. I've seen interest from other teams in using our scripts and I think it could be really useful if they could grab 'em from an Azure Artifacts feed. Granted, I could just do both: Use current approach for our pipelines and publish our packages to Azure Artifacts. It just itches to use two different approaches here.Walter Vos

1 Answers

0
votes

how can I determine which version of my scripts I should be downloading from Azure Artifacts?

If the feature verion is the target version, you could try the following yaml to get its value. See: Repository details for details.

resources:
  repositories:
    - repository: templates
      type: git
      name: PROJECT/cicd_stuff
      ref: releases/v0.21

variables:
  tools.ref: $[ resources.repositories['templates'].ref ]
  
pool:
  vmImage: ubuntu-latest

steps:
- bash: |
    echo "Tools version: $TOOLS_REF"

Also you could try Daniel's solution using tagref: refs/tags/v1.0 # optional ref to pin to by reference to this doc: Use other repositories and Checking out a specific ref.

Update>>Currently there is no available predefined variables regarding to the name that was used to include the repository resource ('templates' in this case). If we know the repository alias, the repository name can be parsed via $[ resources.repositories['templates'].name].

Another finding is that the repository resource will be added as the build artifacts, and we can get it from API:GET https://dev.azure.com/{organization}/{project}/_build/results?buildId={buildId}&view=artifacts&__rt=fps&type=consumedArtifacts(I grab this API from browser developer tool). And buildId can be got using variable Build.BuildId. See: Build variables (DevOps Services) for details. From the response, search consumedSources field to find below json segment, which will return all artifacts, you could find repository resource and all its detailed information. enter image description here