I have a step that builds and deploys my app, like this:
./build
./deploy
Pushing to the repo, an application version is built and deployed. The thing is when the branching off that branch, this pipeline runs again, as designed. This is somewhat troublesome because the deploy script fails (using the same version id). To avoid unnecessary work, I added a check in the build script, which errors when in this situation.
Question: how to avoid running additional scripts in the step, at the same time marking the pipeline as successful, so no email is sent because a failure?
Edit: Also, skip every automatic step after that point.
Thanks in advance!
Hi André,
While I haven't done this in BitBucket Pipelines (we use Bamboo) I still think the concepts are transferable. First, as a part of the script I pass in the system variable for the BitBucket Branch i believe in pipelines this is: 'BITBUCKET_BRANCH'
I then wrap the './deploy' portion of the script in an if statment so that it is only executed when we want it to run. Instead of throwing an error we simply don't execute the deployment when we don't want it to run and that will return a successful result.
I hope that helps!
-James
Hi, yes that's helpful, well at least to understand the problem better.
I guess (haven't tried) I could do this in the beginning of the step's script:
my_command || { echo 'my_command failed' ; exit 0; }
But then the next step would execute normally. I could repeat the command on every step, but in the next step the command would always fail. I would have to set up an artifact to signal the next step not to run.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could check for the file with [[ -f file.txt ]] && exit 0 || echo "continuing..."
Or in my example below try to execute the command I want installed.
pipelines:
default:
- step:
name: 'install files into /usr/local and cache it'
caches:
- usr-local-dir
script:
- aws --version && exit 0 || echo "Installing aws-cli";
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.