Using classic azure pipeline, i am able to checkout code along with alias as "_app" but when i try using below YML, it throws an error.
I checked in lots of places of azure documentation but could not get to know variable to use for "repository alias"
Only 'self', 'none', or a repository alias are supported.
My YML file is
steps:
- checkout: $(Resources.TriggeringAlias)
The checkout
task refers to a pipeline resource. As part of the pipeline run sequence, prior to execution the server attempts to authorize access to resources. This ensures that the author and/or pipeline has permissions to use those resources. It also enables the appropriate approvals + checks. What this means is that any field that refers to resource must be known at compile-time.
Some variables are available at compile time and can be referenced using ${{ variables[...] }}
. Unfortunately, it seems that $(Resources.TriggeringAlias)
is only set when the build reason is ResourceTrigger
. This means you'll always get a validation error if you attempt to use checkout: ${{ variables['Resources.TriggeringAlias'] }}
.
One possibility is changing the checkout
task to use a compile-time expression that defaults to self
if the triggering alias isn't available. We're using the newly introduced iif
expression that uses <condition>, <true-value>, <false-value>
as arguments:
checkout: ${{ iif( eq( variables['Build.Reason'], 'ResourceTrigger'), variables['Resource.TriggeringAlias'], 'self') }}
However, my experimentation shows that the $(Build.Reason)
is always IndividualCI
when triggered from the resources (which feels like a bug or documentation gap). Fortunately, $(Build.Repository.Name)
is populated with the triggering repository. Unfortunately, $(Build.Repository.Name)
is available at compile-time but the value seems to change between compile and runtime.
While it's not ideal you can do the following. This assumes that the aliases of the pipeline is the same as the $(Build.Repository.Name)
:
resources:
repositories:
- repository: RepositoryA
type: git
name: RepositoryA
trigger:
- main
- repository: RepositoryB
type: git
name: RepositoryB
trigger:
- main
steps:
- checkout: RepositoryA
condition: eq( variables['Build.Repository.Name'], 'RepositoryA')
- checkout: RepositoryB
condition: eq( variables['Build.Repository.Name'], 'RepositoryB')