If I create a parameter, I can set its value when I run a pipeline manually. But when the pipeline runs automatically, it uses the default value. When a pipeline runs automatically (say in response to pushing to a repo) is there any way to pass it the value of a parameter?
This is the yaml file I was playing around with. The goal is to be able to control which tests get run in the pipeline.
parameters:
- name: testFiles
type: string
default: cypress/integration/first.spec.js
trigger:
- azure-test
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: "10.x"
displayName: "Install Node.js"
- script: npm install
displayName: "npm install"
- script: npx cypress run --record --key [record key removed] --spec ${{ parameters.testFiles }}
displayName: "run cypress"
When a pipeline runs automatically (say in response to pushing to a repo) is there any way to pass it the value of a parameter?
When running the automatical pipeline, it will only use the default parameter values.
So we can achieve this requirement by changing the default value of parameters.
Based on my test, I have found a convenient method: you could use If expression to check the trigger method (manually or CI). Then you could set the value of the parameters.
Note: We cannot use if expressions when defining parameters, so we need to use variables to pass values.
You could refer to this ticket.
Here is my example:
trigger:
- master
variables:
${{ if eq( variables['Build.Reason'], 'IndividualCI' ) }}:
buildVersion: $(BUILD.SOURCEVERSIONMESSAGE)
${{ if ne( variables['Build.Reason'], 'IndividualCI' ) }}:
buildVersion: cypress/integration/first.spec.js
parameters:
- name: testFiles
type: string
default: $(buildVersion)
pool:
vmImage: ubuntu-latest
steps:
- script: echo ${{ parameters.testFiles }}
displayName: 'Run a one-line script'
The variable $(Build.Reason) is used to confirm the trigger method.
The variable $(BUILD.SOURCEVERSIONMESSAGE) contains the message of the commit.
Here are the steps:


In this case, it is similar to manually running the pipeline to set the parameters value.
When you manually run the pipeline, it will use the defined default value. You can also modify the value when you maually run the pipeline.

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