Deploying Examples


#1

Update: Current Documentation for 2.0 is available here: https://circleci.com/docs/2.0/

CircleCI 2.0 Deployments

This doc assumes that you have already read the overview and configuring docs for CircleCI 2.0.

Deployments in CircleCI 2.0 are now considered “special steps” instead of stages. One common pattern you might use is grouping deploy steps with the same environment in a deployment stage. For example:

#...
    stages:
      deployment:
        workDir: /home/ubuntu/my-project
        steps:
          - type: deploy
              name: "Deploy to staging"
            command: |
              if [ "${CIRCLE_BRANCH}" == "staging" ];
                then ansible-playbook site.yml -i staging;
              fi
          - type: deploy
              name: "Deploy to production"
            command: |
              if [ "${CIRCLE_BRANCH}" == "master" ];
                then ansible-playbook site.yml -i production;
              fi
#...

Here, $CIRCLE_BRANCH is checked to determine which branch (and thus which environment) should be deployed. The syntax here defaults to bash, but you could specify a custom shell as well. Note that YAML uses ‘|’ to indicate the start of a multiline string.

Deployment Examples

Heroku

    stages:
      deployment:
        workDir: /home/ubuntu/<my-project>
        steps:
          - type: deploy
              name: "Deploy to Heroku"
            command: |
              if [ "${CIRCLE_BRANCH}" == "master" ]; then
	        # Install Heroku fingerprint
		echo 'heroku.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu8erSx6jh+8ztsfHwkNeFr/SZaSOcvoa8AyMpaerGIPZDB2TKNgNkMSYTLYGDK2ivsqXopo2W7dpQRBIVF80q9mNXy5tbt1WE04gbOBB26Wn2hF4bk3Tu+BNMFbvMjPbkVlC2hcFuQJdH4T2i/dtauyTpJbD/6ExHR9XYVhdhdMs0JsjP/Q5FNoWh2ff9YbZVpDQSTPvusUp4liLjPfa/i0t+2LpNCeWy8Y+V9gUlDWiyYwrfMVI0UwNCZZKHs1Unpc11/4HLitQRtvuk0Ot5qwwBxbmtvCDKZvj1aFBid71/mYdGRPYZMIxq1zgP1acePC1zfTG/lvuQ7d0Pe0kaw==' >> ~/.ssh/known_hosts
	        git push git@heroku.com:<heroku-app-name>.git
              fi
  • <my-project> — name of repo used on GitHub/Bitbucket
  • <heroku-app-name> — unique app name set in Heroku when created

This example deploys the master branch of the project to Heroku via Git over SSH.


Heroku credentials aren't used
What are the other steps for the yaml file?
We’d like your feedback!
#2

If I create a separate stage deployment after my build stage it doesn’t run. If I simply include the deploy step in the build stage it works fine.

Are separate stages meant to be used for this? The getting started guide doesn’t seem to mention the purpose of stages…


#3

We currently offer one stage. However, the end goal is to offer multiple stages offering you more granular control of when and how items in your build occur. This isn’t quite ready for testing yet but hang in there. We have it out soon!

Is this blocking you from using CircleCI 2.0? Is there anything we can do to help you?


#4

Ah, ok. The documentation isn’t clear about this. I’m not blocked, I just switched to having only 1 stage and it is fine. Thanks.


#5

Hey @tsloughter, you were completely right about the formatting. I’m adjusting the code sample so future generations won’t run into the same issues. I commend your eagle eyes!


#6

Is there a way to access the heroku toolbelt? We use it while deploying to heroku to trigger the heroku maintenance page


#7

I don’t see why you can’t install it on the image you’re using.


#8

Do you have an example of what that would look like? Do you mean installing the heroku toolbelt into the shared container that we’re currently using as one of the steps of circle.yml? Or something like creating and publishing our own container on docker hub?


#9

The latter. Just build a Docker image with everything you need, with the exception of anything private/sensitive.


#10

#11