Environment: Azure DevOps Server 2022.0 with Windows-agents
We have several big Windows projects in different Git-repos. They should be built by a single YAML-pipeline, using project-specific templates. I created a YAML repo for anything pipeline.
I would like the triggering repo to set a variable that I can use further down the line as part of a template name, and in the build id. Not only that, I would like to be able to specify, for a manual run, which project to use, and use that information in the same way.
Azure-pipelines.yml:
resources:
repositories:
- repository: AAA
type: git
name: AAA
ref: main
trigger:
branches:
include:
- main
- repository: BBB
type: git
name: BBB
ref: main
trigger:
branches:
include:
- main
- repository: YAML
type: git
name: YAML-Automation
ref: main
trigger:
- none
parameters:
- name: projectToBuild
displayName: "Project to build:"
type: string
default: AAA
values:
- AAA
- BBB
- CCC
variables:
productName: $(Build.Repository.Name)
productVersion: 5.0.1
name: $(Build.Repository.Name)_$(productVersion)_$(Date:yyMMdd)$(Rev:rr)
I guess because a trigger from a repo happens after the YAML code has been compiled, the information is not available when “name” is set. But when I output the variable, it shows the correct information:
When repo BBB triggers,
echo Build.Repository.Name = $(Build.Repository.Name)
shows BBB, but the build has the name
#YAML-Automation_5.0.1_24070505
The checkout should be only for the YAML-repo and for the triggering one, so I need the name of the triggering repo again, which is empty.
Further down the line, I would like to use, for example, a template jobStuff-$(productname).yml, but productName is empty, and it doesn’t work.
Finally, for a manual run, I would like to use the value of the manual project selection, projectToBuild, as input for productName, guess that would just require an “if manual”, as in $[eq(variables[‘Build.Reason’], ‘Manual’)].
Should my general approach work?
What could I do to get the name of the triggering into a usable variable?