If (not) startswith mutually exclusive steps #26386
-
Hi, I am trying to have two mutually exclusive steps in my workflow, based on an input parameter’s value:
But if I specify ‘dev’ as input, both steps are executed. If I specify ‘release/0.0.0’ as input, also both steps get executed. Whatever input I give, always both steps are executed. As if the if statements / startswith don’t work at all. I tried also:
None of them seem to work. I read https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions, but there’s no example of how to use the ‘not’ operator. Valentijn |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
You are using the incorrect expression syntax for the if conditional in your workflow.
There are few points you need to know when setting if conditionals (jobs.<job_id>.if or jobs.<job_id>.steps.if) in your workflow:
In addition, you can enable debug logging to view the result of the if conditionals for each step from the debug logs. From the logs, you can see how the job evaluates the if conditionals for each step and returns the final result (true or false). |
Beta Was this translation helpful? Give feedback.
-
Wow, best reply ever. Thank you @brightran ! |
Beta Was this translation helpful? Give feedback.
-
brightran:
That’s really good to know. Are there other cases which require |
Beta Was this translation helpful? Give feedback.
-
I suppose this has less to do with GitHub Actions and more with YAML in general.
With the if condition wrapped in
|
Beta Was this translation helpful? Give feedback.
-
why is this not in the official documentation? 👍 @BrightRan |
Beta Was this translation helpful? Give feedback.
@valentijnscholten,
You are using the incorrect expression syntax for the if conditional in your workflow.
Change them like as this can work:
name: Use existing release branch
if: ${{ startsWith(github.event.inputs.from_branch, 'release/') }}
run: |
echo "NEW_BRANCH=${{ github.event.inputs.from_branch }}" >> $GITHUB_ENV
There are few points you need to know when setting if conditionals (jobs.<job_id>.if or jobs.<job_id>.steps.if) in your workflow:
If you want to use the expression syntax “${{ }}