Enhancements to the Rollbar Deploy API

Enhancements to the Rollbar Deploy API

October 9th, 2018 • By Jesse Gibbs

Rollbar introduced Versions a few months ago, providing developers a way to easily see whether their most recently deployed code changes are introducing new or reactivated errors.

As a follow-on improvement, we've updated our Deploys API so you can notify Rollbar immediately when starting a deploy as well as when it completes.

Notifying Rollbar immediately when a deploy starts will ensure that notifications about the new version will include as much information as possible, including the number of commits since the previous deploy as well as the user who started the deploy.

New Version notification in Slack

Read on to see how to use the updated Deploy API to notify Rollbar when your deploy starts and finishes.

Starting a Deploy

For this post I'll show you how to notify Rollbar using a Bash deploy script, but any tool that is able to make HTTP calls can be used to report deploys to Rollbar. The example relies on curl and jq, both of which can be downloaded and intalled for free, and come pre-installed in many environments.

At the start of your deploy script, you'll need to send a POST request to report a new deploy and save the deploy_id into a variable so it can be used later:

# ...
# set variables for the POST command
ROLLBAR_ACCESS_TOKEN=YOUR_POST_SERVER_ITEM_ACCESS_TOKEN_HERE
ENVIRONMENT=development
GIT_SHA=YOUR_GIT_SHA_HERE
# ...

ROLLBAR_DEPLOY_ID=`curl https://api.rollbar.com/api/1/deploy/ \
                      --form access_token=$ROLLBAR_ACCESS_TOKEN \
                      --form environment=$ENVIRONMENT \
                      --form revision=$GIT_SHA \
                      --form local_username=$USER \
                      --form status=started | jq -r '.data.deploy_id'`

# Additional steps for your deploy...

Running deploys will appear in the web app with a status icon: Deployment in-progress

Finishing a deploy

After your deploy process has completed, you can update the deploy status by sending a PATCH request as follows:

curl -X PATCH \
https://api.rollbar.com/api/1/deploy/$ROLLBAR_DEPLOY_ID?access_token=$ROLLBAR_ACCESS_TOKEN \
--data '{"status":"succeeded"}'

If your deployment failed, you can notify Rollbar of that status instead:

curl -X PATCH \
https://api.rollbar.com/api/1/deploy/$ROLLBAR_DEPLOY_ID?access_token=$ROLLBAR_ACCESS_TOKEN \
--data '{"status":"failed"}'

Your full script should look something like the following:

# set variables for the POST command

ROLLBAR_ACCESS_TOKEN=YOUR_POST_SERVER_ITEM_ACCESS_TOKEN_HERE
ENVIRONMENT=development
GIT_SHA=YOUR_GIT_SHA_HERE

ROLLBAR_DEPLOY_ID=`curl https://api.rollbar.com/api/1/deploy/ \
                      --form access_token=$ROLLBAR_ACCESS_TOKEN \
                      --form environment=$ENVIRONMENT \
                      --form revision=$GIT_SHA \
                      --form local_username=$USER \
                      --form status=started | jq -r '.data.deploy_id'`

# Do the rest of your steps for your deploy here...

# set a DEPLOY_STATUS variable to either 'succeeded' or 'failed', then update Rollbar...

curl -X PATCH \
https://api.rollbar.com/api/1/deploy/$ROLLBAR_DEPLOY_ID?access_token=$ROLLBAR_ACCESS_TOKEN \
--data '{"status":"'"$DEPLOY_STATUS"'"}'

Finished deploys will show up with a status icon indicating whether they succeeded, failed, or timed out:

Finished deploys with status

Deploys that are started but not updated after a period of time are automatically marked as timed out. You can control how long the timeout period is by going to Settings ➜ Deploys and entering the timeout period (in minutes).

Conclusion

Using the new status option in Rollbar deploy API calls will ensure that your New Version notifications work correctly and accurately reflect what happens with your deploys.

If you haven’t already, sign up for a 14-day free trial of Rollbar and see how we can help you release code updates with confidence.

Get the latest updates delivered to your inbox.