How can I set a logical statement to skip the commands if the branch matches the regex?
I tried to add the following to filter out if branch are created by Dependabot but seems like the CircleCI build is not accessing the logical statements and continue to run even if my branch name is dependabot.workflow
Thanks for that. But that doesn’t really help. Instead, I just added the following if else on the command to skip it if the branch name starts with dependabot.
commands:
build-push-docker-image:
description: "Build docker image command"
steps:
run:
name: Run docker build
command: |
if [[ ! << pipeline.git.branch >> =~ ^dependabot.* ]]; then
docker build .
else
echo "skip this run step"
fi
Unfortunately, this solution won’t stop the resource allocation. It would better to have at least two condition operators like starts_with and ends_with@Henna, otherwise, thinking on the workflow level, if you have 3 jobs which should be filtered by branch, you have to repeat the filter/branches/only over and over again.
That is a great point! At the time when this post was created, we did not support using regular expressions for branch filtering on a workflow level. We do now!
We do not currently have a starts_with key but you could use a regular expression in a logic statement to do what you described above.
You can also create an feature request on CircleCI’s ideas page for starts_with & ends_with keys.