Codeship Integration

Codeship is a hosted continuous delivery service that focuses on speed, reliability and simplicity. It supports a variety of programming languages (Ruby on Rails, Node.js, PHP, Java, Go, Dart, etc.) and deployment platforms (Amazon Web Services, Heroku, Google App Engine, etc.). The practice of continuous integration involves repeated automated testing and code merging with notifications to alert developers to problems in their code in real time. Codeship combines this with the practice of continuous delivery, which provides for regular code deployment once changes have passed automated tests. Essentially, when you push your code to GitHub (or Bitbucket), Codeship rebuilds your application on its secure servers and runs your automated tests. If the tests fail, it notifies your development team via email or integration.

What does OpsGenie offer Codeship users?

By using OpsGenie Codeship Integration, you can forward Codeship build alerts to OpsGenie. OpsGenie can determine the right people to notify based on on-call schedules, using email, text messages (SMS), phone calls and iOS & Android push notifications, and escalating alerts until the alert is acknowledged or closed.


Functionality of the integration

  • When a build alert is created in Codeship, an alert is created in OpsGenie automatically through the integration.

Add Codeship Integration to OpsGenie

  1. Please create an OpsGenie account if you haven't done already
  2. Go to OpsGenie Codeship Integration page,
  3. Specify who should be notified for Codeship alerts using the "Teams" field. Auto-complete suggestions will be provided as you type.
  4. Click on "Save Integration".

Configuration in Codeship Pro

  • Setting Your API Key
    1. You will need to add your OpsGenie API key to your encrypted environment variables that you encrypt and include in your codeship-services.yml file.
  • Sending Alerts
    1. You need to add API calls to OpsGenie, in your codeship-services.yml file.
    2. There are a couple common ways you may do this:
      • To alert of a successful deployment, as the last step in your pipelines
      • Combined with your deployment commands in a script, to alert of a failed deployment.
    3. This example will run a deployment command, and then a script that would theoretically call the relevant OpsGenie API endpoints if that deployment is successful (meaning, if it moves on to the next step.)
    4. 
      - name: deploy
        service: app
        tag: master
        command: your deployment commands here
      
      - name: opsgenie
        service: app
        tag: master
        command: opsgenie.sh
                      
    5. Alternatively, you could combine your deployment scripts with an OpsGenie API call, in a custom script that would alert OpsGenie if a deployment command fails before ultimately surfacing an exit status code 1 (or or anything other than 0) to instruct Codeship to fail to the build:
    6. 
       - name: deploy
         service: app
         tag: master
         command: deploy.sh
                      
    7. The OpsGenie API call itself, however implemented, will likely look similar to:
    8. 
      curl -XPOST 'https://api.opsgenie.com/v1/json/alert' -d '
      {
          "apiKey": "YOUR_API_KEY",
          "message" : "Deployment Failed",
          "teams" : ["ops", "managers"]
      }'
                      
    9. Although it is worth noting that OpsGenie API provides a variety of endpoints and services you can implement.

Configuration in Codeship Basic

  • Setting Your API Key
    1. You will need to add your OpsGenie API key to your to your project’s environment variables.
    2. You can do this by navigating to Project Settings and then clicking on the Environment tab.
  • Sending Alerts
    1. Next, you will need to add API calls to OpsGenie via a custom-script deployment added to your [deployment pipelines, most likely to alert of a successful deployment or combined with your deployment commands in a script to alert of a failed deployment.
    2. The OpsGenie API call will likely look similar to:
    3. 
      curl -XPOST 'https://api.opsgenie.com/v1/json/alert' -d '
      {
          "apiKey": "YOUR_API_KEY",
          "message" : "Deployment Failed",
          "teams" : ["ops", "managers"]
      }'
                        
    4. Although it is worth noting that OpsGenie API provides a variety of endpoints and services you can implement.

Sample Webhook Message from OpsGenie Codeship Plugin

{
  "build": {
    "build_url":"https://www.codeship.com/projects/10213/builds/973711",
    "commit_url":"https://github.com/codeship/docs/
                  commit/96943dc5269634c211b6fbb18896ecdcbd40a047",
    "project_id":10213,
    "build_id":973711,
    "status":"testing",
    # PROJECT_FULL_NAME IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE
    "project_full_name":"codeship/docs",
    "project_name":"codeship/docs",
    "commit_id":"96943dc5269634c211b6fbb18896ecdcbd40a047",
    "short_commit_id":"96943",
    "message":"Merge pull request #34 from codeship/feature/shallow-clone",
    "committer":"beanieboi",
    "branch":"master"
  }
}

Sample alert