Reputation: 13
I have a job template:
parameters:
- name: is_release_version
type: boolean
default: false
jobs:
- job: 'Build'
displayName: 'display name'
But I would like the job name to be "Build_Test" or "Build_Release" depending on my parameter.
I tried:
parameters:
- name: is_release_version
type: boolean
default: false
variables:
- ${{ if eq(parameters.is_release_version, false) }}:
- name: name_ext
value: Test
- ${{ if eq(parameters.is_release_version, true) }}:
- name: name_ext
value: Release
jobs:
- job: 'Build_${name_ext}'
displayName: 'display name'
But "variables" is not expected at this level. I tried passing the name directly as parameter and that works, but I would rather fix the possibilities in the template.
I also tried:
parameters:
- name: is_release_version
type: boolean
default: false
jobs:
- ${{ if eq(parameters.is_release_version, false) }}:
- job: 'Build_Test'
- ${{ if eq(parameters.is_release_version, true) }}:
- job: 'Build_Prod'
displayName: 'display name'
But it does not work either. I guess the problem is the indentation of "displayName", and that would mean I would have to duplicate the whole job for the two if.
For now I will pass the name, but I am interested in any method to change the job name in a template.
Upvotes: 1
Views: 2556
Reputation: 18978
The variable called format you used in job name is not correct. You can try to use Build_${{variables.name_ext}}
:
jobs:
- job: 'Build_${{variables.name_ext}}'
displayName: 'Build_${{variables.name_ext}}'
See the execution result while I define is_release_version value
as true
:
You can see that it can pass name_ext
value into job name.
Upvotes: 3