Rely upon your CI's features for conditional execution
It is very tempting to have conditional checks inside a shell script, e.g. checking for a specific branch name, and then exiting if those conditions are not met. Instead, check your CI's conditional features to implement those checks, e.g.
- Conditional tasks in Bamboo
- Conditions for job execution in GitHub Actions
whendirectives for Jenkins Pipelines.
Letting the CI decide if a shell script has to be executed, has two advantages:
- It makes your shell script more readable as you don't have to deal with checking for branch names.
- The shell script will not be executed by the CI. This means that your the conditional task does not appear in the workflow execution. The workflow is better understandable: There is no confusion, why a -maybe critical- script has been executed, even if has technically not been doing anything.