Reputation: 606
I'm looking for an elegant or inelegant solution for failing a step in ADO pipelines when git commands return unexpected and unwanted results. In general, I call git with a bash task, like so:
steps:
- bash: |
git merge ${{ parameters.sourceBranch }}
If the merge fails, I would like this step to fail in my ADO pipeline. How would I go about doing that?
Upvotes: 0
Views: 1018
Reputation: 1791
Would failOnStderr work? It looks like the bash step you're using is similar to script here.
Upvotes: 0
Reputation: 606
Found a somewhat elegant solution just by setting a variable to the output:
git merge ${{ parameters.sourceBranch }}
status=$?
[ $status -eq 0 ] || exit $status
$? is the last status code. The next line says "if the last status was 0, continue on, else/or: exit with that status code".
Upvotes: 0
Reputation: 3582
Given that the result of the git merge command should be not successful on bash I created the below bash condition. If result is correct nothing will be done, else exit for the bash will be returned
if git merge ${{ parameters.sourceBranch }} > /dev/null 2>&1; then
echo success
else
exit 1
fi
Upvotes: 1