i have a variables declared in yaml templates like
# File: vars.yml
variables:
- name: firstvar
value:'first var value'
- name: secondvar
value:'second var value'
and in pipeline i'm using extend template
trigger:
- none
extends:
template: resource-template.yml
paramters:
uservariablestemplate: <i want to pass above variable yaml template here>
because my extend template using other variables so this user defined variables should be used in there
# File: resource-template.yml
parameters:
- name: uservariablestemplate
type: string
default: none
resources:
repositories:
- repository: samplerepo
type: git
name: myproject/myrepo
variables:
- template: centralvariables.yml@samplerepo
- template: <i want to use variable template from user here>
steps:
- script: echo "Testing resource template"
Any help would be appreciated. or any other workaround to achieve this.
You can just pass the variable template file name to the parameters. For below example:
trigger:
- none
extends:
template: resource-template.yml
paramters:
uservariablestemplate: vars.yml
Then in the template resource-template.yml
, retrieve the variable template using ${{parameters.uservariablestemplate}}
. See below example:
parameters:
- name: uservariablestemplate
type: string
default: none
resources:
repositories:
- repository: samplerepo
type: git
name: myproject/myrepo
variables:
- template: centralvariables.yml@samplerepo
- template: ${{parameters.uservariablestemplate}}
steps:
- script: echo "Testing resource template"
If the variable template file resides in another repo. You need to define the repo in the repo resources section. For below example:
parameters:
- name: uservariablestemplate
type: string
default: none
resources:
repositories:
- repository: samplerepo
type: git
name: myproject/myrepo
- repository: variableRepo
type: git
name: myVariableRepo
variables:
- template: centralvariables.yml@samplerepo
- template: ${{parameters.uservariablestemplate}}@variableRepo
steps:
- script: echo "Testing resource template"
Update:
To dynamically set the repo name, you can try using runtime parameters. See below: Define a runtime parameter repo
:
trigger: none
parameters:
- name: repo
type: string
default: none
extends:
template: resource-template.yml
parameters:
uservariablestemplate: vars.yml
Then you can refer to the repo by ${{parameters.repo}}
in the following yaml.
When you run your pipeline. You will be able to set the repo name:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With