I have a condition to run a task in azure job template conditionally if value of parameter is not null, however the task runs even if value of parameter is null.
parameters:
- name: 'new_tag_value'
default: ''
type: string
- task: Bash@3
displayName: 'Update Image tag in helm chart'
inputs:
targetType: filePath
filePath: '${{ parameters.bash_script_path_image_tag_update }}'
arguments: '${{ parameters.new_tag_value }} ${{ parameters.svc_value_File }}'
condition: and(succeeded(), ne('${{ parameters.new_tag_value }}', ''))
2
Answers
When the parameter is null, the check compares null with an empty string. Null is not equal to an empty string, the ne expression therefore evaluates to true and executes.
You can reference the sample below to update your YAML files to make the condition work as expected in the pipeline.
The template YAML file:
Steps_Temp/insert-step.yml
The main YAML file:
azure-pipelines.yml
Result
When triggering a new run of the pipeline, if directly using the
default
value ofMyTag
and providing a new value, theBash@3
task will be skipped.When triggering a new run of the pipeline, if providing a new value which is not null or whitespace to
MyTag
, theBash@3
task will run.