How to define a set of common commands for deployment

circle.yml

#1

The example deployment section of circle.yml from your documentation looks like this:

deployment:
  prod:
    branch: master
    commands:
      - ./deploy.sh

That’s fine, but what if I want to have something like this?

deployment:
  staging:
    branch: master
    commands:
      - bash-command-1
      - bash-command-2
      - bash-command-3
      - ./deploy_staging.sh
  prod:
    branch: release
    commands:
      - bash-command-1
      - bash-command-2
      - bash-command-3
      - ./deploy_production.sh

you see, both deployments need bash-commands to be run, but they should be only run when I reach the deployment stage (tests have passed) - I’m wondering what’s the best way to implement it. The other option I came up with would look like this:

deployment:
  staging_production:
    branch: [master, release]
    commands:
      - bash-command-1
      - bash-command-2
      - bash-command-3
      - if [ $CIRCLE_BRANCH = 'master' ]; then ./deploy_staging.sh; fi
      - if [ $CIRCLE_BRANCH = 'release' ]; then ./deploy_production.sh; fi

But this seems like a hacky solution - could I just put multiple commands into deployment which are called always? like

deployment:
  commands:
    - bash-command-1
    - bash-command-2
    - bash-command-3
  staging:
    branch: master
    commands:
      - ./deploy_staging.sh
  prod:
    branch: release
    commands:
      - ./deploy_production.sh

Or what else would be the preferred way?


#2

I don’t think this is a bad solution. Ultimately if you need to run the same things regardless of the branch, why not wrap those in a script called deploy_common.sh and then call that?


#3