Assume that enable_datasync_job
is defined in the UI as false
Option 1
To override the above variable that is defined in the UI, you can add this bash task to your pipeline
- bash: |
echo $(ENABLE_DATASYNC_JOB) # outputs as false
echo "##vso[task.setvariable variable=enable_datasync_job;]true" # override
- bash: |
echo $(ENABLE_DATASYNC_JOB) # outputs as true
Since your template accepts the parameter of type boolean, you would have something like the below
# template.yml
parameters:
- name: enable_datasync_job
type: boolean
steps:
- bash: |
echo $(ENABLE_DATASYNC_JOB)
And your main yml file
# azure-pipelines.yml
steps:
- bash: |
echo "##vso[task.setvariable variable=enable_datasync_job;]true" # override
- template: template.yml
parameters:
enable_datasync_job: $(enable_datasync_job) # fail
But the above azure-pipelines.yml
will fail because of typecasting of string into boolean. Check this SO post for more details
/azure-pipelines.yml (Line: 11, Col: 28): The 'enable_datasync_job'
parameter value '$(enable_datasync_job)' is not a valid Boolean.
According to the above post, you can change the data type of parameter to string in your template.yml
parameters:
- name: enable_datasync_job
type: string
Final result of option 1
# template.yml
parameters:
- name: enable_datasync_job
type: string
steps:
- bash: |
echo $(ENABLE_DATASYNC_JOB) #outputs true
# azure-pipelines.yml
steps:
- bash: |
echo "##vso[task.setvariable variable=enable_datasync_job;]true" # override
- template: template.yml
parameters:
enable_datasync_job: $(enable_datasync_job)
Option 2
If you are looking to just pass the value true
to your template without overriding the pipeline variable, you can reference the value that you passed like this
# template.yml
parameters:
- name: enable_datasync_job
type: boolean
steps:
- bash: |
echo ${{ parameters.enable_datasync_job }} # outputs true
echo $(ENABLE_DATASYNC_JOB) # outputs false
# azure-pipelines.yml
steps:
- template: template.yml
parameters:
enable_datasync_job: true
The reason why it was returning False
for you is because you have used this expression while passing value to the parameter
${{ eq(variables.enable_datasync_job, 'true') }}
According to the documentation, the eq
function
Evaluates True if parameters are equal
You tried to evaluate if the UI variable was equal to true instead of setting it
The expression that you used above will always return False
because false(UI variable value) is not equal to true(set in the expression)