Reputation: 65
that my if condition and inside I have task, and once build from dev branch running is Still running and not skip on the task.
what wrong with that if condition?
EDIT:
my condition are not working:
- ${{ if or(ne(variables['Build.SourceBranchName'], 'refs/heads/dev') , ne(variables['Build.SourceBranchName'], 'refs/heads/main')) }}:
Upvotes: 0
Views: 876
Reputation: 35099
I want to filter it to get inside the if only from dev branch or main branch..
From your YAML sample to set the if expression, you need to change the operator from or
to and
.
steps:
- ${{ if and(ne(variables['Build.SourceBranchName'], 'dev') , ne(variables['Build.SourceBranchName'], 'main')) }}:
- script: env | sort
When you use the and
operator, the task will only run if the source branch name is not dev
and master
.
When you use the or
operator, one of the two conditions needs to be met to run the task. When branch is dev, it satisfies ne(variables['Build.SourceBranchName'], 'master'
so task will run.
Upvotes: 0
Reputation: 1646
Is your branch exact dev
or more like dev/*
.
The if condition now expects exactly dev
.
Try something like this example:
not(containsValue(variables['Build.SourceBranch'], ‘dev’ ))
Upvotes: 1