Right now our deployments are done manually, we'd love to move these into bitbucket pipelines.
Here's what I need to do for our deployments:
Other potential important information:
We use different branches for staging/development, so would like to trigger the deploy to the staging server on push to the "staging" branch, and the deploy to the production server on push to the "master" branch.
/cc @Linette
Hi @hailwoodnz
Bitbucket pipelines supports branch deployment workflows natively so this is fairly straight forward. You want to define a separate pipeline in your bitbucket-pipelines.yml file for each of your deployment branches, for example:
pipelines:
default: # the default pipeline will just run your build and test commands
- step:
name: Build and test
script:
- npm install
- npm test
branches:
staging: # the staging branch pipeline will deploy to the staging environment
- step:
name: Build and test
script:
- npm install
- npm test
- step:
name: Deploy to staging
deployment: staging
script:
- npm run staging
- git pull ...
master: # the master branch pipeline will deploy to the production environment
- step:
name: Build and test
script:
- npm install
- npm test
- step:
name: Deploy to production
deployment: production
script:
- npm run prod
- git pull ...
With this configuration:
Because the deployment steps have been marked with their respective environments you'll also be able to track the status of those environments on the deployments dashboard in Bitbucket.
The yml file is read from the branch on which the push occurs so be sure to merge this configuration to both staging and master branches.
There's also some duplicate step definitions in there that can be cleaned up using shared scripts or yml anchors.
I hope this helps!
Sam
Thanks for the detailed answer @StannousBaratheon,
This looks like it should cover everything nicely,
I was just reading through about the deployments and note it says
Currently Bitbucket Deployments supports deploying to
test
,staging,
andproduction
environments and they must be listed in this order in the yml file.
Given that we have only staging and production, and given your example above I assume that if we don't have a given environment it doesn't need to be listed?
If this is the case perhaps the note could be updated to
Currently Bitbucket Deployments supports deploying to
test
,staging,
andproduction
environments and if deploying to these environments they must be listed in this order in the yml file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's correct @hailwoodnz, the environments must be listed in that order if they're being used in the same pipeline but it's not required that you use all 3 environments.
In this example you actually have environments defined in different pipelines because you have a branch deployment workflow so the order requirement is also irrelevant.
I'll pass on your suggestion to our documentation team. Thanks for the feedback :)
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.