It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to deploy to remote server after building assets in pipeline?

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:

  1. npm install
  2. npm run prod
  3. git pull on remote server
  4. run another bash command on the remote server
  5. scp specific files (built assets via the npm run prod) to remote server

 

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

1 answer

1 accepted

1 vote
Answer accepted

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:

  • pushes to master will run the master branch pipeline and deploy to production
  • pushes to staging will run the staging branch pipeline and deploy to staging
  • pushes to any other branch will run the default pipeline which only runs the build and test step

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 teststaging,and production 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 teststaging,and production environments and if deploying to these environments they must be listed in this order in the yml file.

Like Surya Van Lierde likes this

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 :)

Like Surya Van Lierde likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Atlassian supported Jenkins integration for Bitbucket Server

We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...

1,088 views 3 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you