Releasing into an environment

One of the most useful aspects of having your build mapped as a pipeline, is being able to know exactly what is in a particular environment. For example, you might have a User Acceptance Testing environment into which you want GoCD to automatically deploy your binary. Due to process restriction within your company, you might want to manually install a binary yourself, but have GoCD still retain the information of what is currently released.

Example usages

Automatically deploy to UAT

For this example, we’ll assume that there is already an ant task defined in your build that will take a binary and deploy it to your environment. A separate task will verify the install was successful. If it is not, a task will run to rollback the deployment. We will also assume that earlier in the pipeline there is a dist stage with a create-installers job that will have already created the binary for us to use.

  1. <tasks>
  2. <fetchartifact stage="dist" job="create-installers" srcdir="pkg" dest="installers" />
  3. <ant target="deploy_to_uat" />
  4. <ant target="verify_uat_works_correctly" />
  5. <ant target="rollback_to_previous_install_in_uat">
  6. <runif status="failed" />
  7. </ant>
  8. </tasks>

When you are ready to deploy something into the UAT environment…

  • Navigate to the pipeline history page
  • Find the check-in you want to deploy
  • Click on the manual transition into the UAT stage

Deploy to an environment - 图1

  • When the deploy is successful, the stage will be green and the UAT environment will contain the selected check-in

Deploy to an environment - 图2

  • When the deploy fails for some reason, the stage will be red and the UAT environment will contain the original check-in

Deploy to an environment - 图3

Manually deploy to production

For this example, we’ll assume that there is a known way to rollback to a previous installation. We will also assume that earlier in the pipeline there is a dist stage with a create-installers job that will have already created the binary for us to use.

When you are ready to deploy something into the production environment…

  • Navigate to the pipeline history page
  • Find the check-in you want to deploy
  • Click on the details link of the dist stage

Deploy to an environment - 图4

  • Download the installer binary in the artifacts tab

Deploy to an environment - 图5

  • Manually install the binary into production
  • If there are issues, manually rollback to the last known good installation
  • If everything seems to be working correctly, click on the manual transition into the production stage

Deploy to an environment - 图6