This article is about General Codeship Configuration.

Tracking Deployments With OpsGenie

Estimated Reading Time: 2 mins

About OpsGenie

OpsGenie lets you send alerts and notifications about critical events to your on-call or development team.

Their documentation does a great job of providing more information, in addition to the setup instructions below.

Codeship Pro

Setting Your API Key

To get started, 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

Next, you will need to add API calls to OpsGenie, in your codeship-steps.yml file.

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.

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

- name: deploy
  service: app
  tag: master
  command: your deployment commands here

- name: opsgenie
  service: app
  tag: master
  command: opsgenie.sh

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:

- name: deploy
  service: app
  tag: master
  command: deploy.sh

The OpsGenie API call itself, however implemented, will likely look similar to:

curl -XPOST 'https://api.opsgenie.com/v1/json/alert' -d '
{
    "apiKey": "YOUR_API_KEY",
    "message" : "Deployment Failed",
    "teams" : ["ops", "managers"]
}'

Although it is worth noting that their API provides a variety of endpoints and services you can implement.

Codeship Basic

Setting Your API Key

You will need to add your OpsGenie API key to your to your project’s environment variables.

You can do this by navigating to Project Settings and then clicking on the Environment tab.

Sending Alerts

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.

The OpsGenie API call will likely look similar to:

curl -XPOST 'https://api.opsgenie.com/v1/json/alert' -d '
{
    "apiKey": "YOUR_API_KEY",
    "message" : "Deployment Failed",
    "teams" : ["ops", "managers"]
}'

Although it is worth noting that their API provides a variety of endpoints and services you can implement.

Need More Help?

Get in touch if you need more help, or post on Stack Overflow using the tag #Codeship.

  • Ask The Helpdesk A Question
  • Code Examples And Sample Projects
    • Was This Article Helpful?