Hi, I have a pipeline that some stages are the same for multiple branches, like compile and tests, but when I need to deploy using the pipeline I want to specify what environment will receive the deploy, now Im doing conditions inside the script like: When branch is production, deploy to production, when branch is staging, deploy to staging.
I want to do something like this, is it possible?
pipelines:
branches:
'{staging, production}':
- step:
name: Build, Tests
caches:
- pip
script:
- build something
- test something
staging:
- step:
name: Deploy
script:
- Deploy to staging
production:
- step:
name: Deploy
script:
- Deploy to production
When I run the pipeline like this just scripts for "{staging and production}" runs.
Thanks for help.
Hello Lucas,
Currently there's no way to share steps between pipelines, so you'll need to define duplicate behaviour in each pipeline.
For example:
pipelines:
branches:
production:
- step:
name: build & test
script:
- ./build-app
- ./run-tests
- step:
name: Deploy to production
script:
- ./deploy-to-production
staging:
- step:
name: build & test
script:
- ./build-app
- ./run-tests
- step:
name: Deploy to staging
script:
- ./deploy-to-staging
To remove command duplication, you can store the commands you need to run inside of a script file and reference that in your bitbucket-pipelines.yml instead. Like so:
You can also use default to define behaviour that will run on all branches that don't match any other rules.
So overall, you could end up with a configuration like:
pipelines:
default: # runs on all branches except production or staging.
- step:
name: build & test
script:
- ./build-app
- ./run-tests
branches:
production:
- step:
name: build & test
script:
- ./build-app
- ./run-tests
- step:
name: Deploy to production
script:
- ./deploy-to-production
staging:
- step:
name: build & test
script:
- ./build-app
- ./run-tests
- step:
name: Deploy to staging
script:
- ./deploy-to-staging
Thanks,
Phil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.