Reputation: 628
I have a pretty simple Azure Pipelines YAML file like:
pool:
vmImage: 'ubuntu-18.04'
strategy:
matrix:
debian:
img: 'debian:latest'
fedora:
img: 'fedora:latest'
arch:
img: 'archlinux:latest'
opensuse:
img: 'opensuse/leap:latest'
container: $[ variables['img'] ]
steps:
- script: printenv
displayName: Dump env
- script: make
displayName: Build the project
Which does nothing more than building the same project on each of the four containers enlisted above.
It works, but I'd like to have also a step that uses the name of the job (debian, fedora, etc.) for running a special script.
How can I get access to the job's name in steps
? Is there something like $(job)
?
Upvotes: 3
Views: 2995
Reputation: 41765
You have the pre-defined variable $(Agent.JobName)
that you can use. for example:
steps:
- script: echo $(Agent.JobName)
displayName: echo $(Agent.JobName)
Will give this output:
Upvotes: 3
Reputation: 771
When I encountered a similar situation, I just created another matrix variable to solve the issue.
With your pipeline, it would look like
pool:
vmImage: 'ubuntu-18.04'
strategy:
matrix:
debian:
job: debian
img: 'debian:latest'
fedora:
job: fedora
img: 'fedora:latest'
arch:
job: arch
img: 'archlinux:latest'
opensuse:
job: opensuse
img: 'opensuse/leap:latest'
container: $(img)
steps:
- script: printenv
displayName: Dump env
- script: make
displayName: Build the project
- script: echo $(job)
displayName: echo $(job)
Upvotes: 0