07/05/2016 - 1 minute read

How to Notify New Relic of Deployments From AppVeyor

Written by

Gary Lewis Cheetham

Automotive marketing specialist from Manchester, UK

During app deployments, previous company policy required us to prepare a sacrifice so that the favour of the gods might shine upon us. I was first asked to see if this process could be automated to save overhead - but I soon realised that we could ensure deployments went smoothly without paying the salaried workers in the embalming-and-sacrificing department at all!

Now we use New Relic to get error rate metrics, and with a POST request to the New Relic API we can even track error rates between, and since the last, deployment. It's much easier to discern our fortunes this way than with haruspicy.

To set up deployment tracking in New Relic when you deploy with AppVeyor, you just need to add this POST request into a post-deploy PowerShell script.

To use the API, you'll need to first generate an API key by going to Account Settings -> Integrations -> API Keys in the New Relic dashboard.

Here's the PowerShell one-liner that we ended up using to send the POST request

Invoke-RestMethod -Uri https://api.newrelic.com/deployments.xml -Method Post -Headers @{"x-api-key"="YOUR_API_KEY"} -Body @{"deployment[application_id]"="YOUR_APPLICATION_ID"; "deployment[description]"="Your Application Deployment"}

The application id is generally just the name of the application in New Relic.

This is very simple, and will work just fine when added as a post-deploy script in AppVeyor. Here's an example appveyor.yml with the post-deploy script added.

branches:
  only:
  - master
  - develop
configuration:
- Release
force_https_clone: true
build:
  # Your build configuration
deploy:
- provider: WebDeploy
  # Your deploy configuration
after_deploy:
- ps: Invoke-RestMethod -Uri https://api.newrelic.com/deployments.xml -Method Post -Headers @{"x-api-key"="YOUR_API_KEY"} -Body @{"deployment[application_id]"="YOUR_APPLICATION_ID"; "deployment[description]"="Your Application Deployment"}

Notice how the PowerShell script is added under after_deploy?

But wait! It get's much better. We can take advantage of AppVeyor's built-in environment variables to notify New Relic of the build number along with the deployment.

It just takes a little of PowerShell's easy string interpolation and we can inline the environment variables provided by AppVeyor into the deployment description.

Invoke-RestMethod -Uri https://api.newrelic.com/deployments.xml -Method Post -Headers @{"x-api-key"="YOUR_API_KEY"} -Body @{"deployment[application_id]"="YOUR_APPLICATION_ID"; "deployment[description]"="Build $env:APPVEYOR_BUILD_ID commit ID $env:APPVEYOR_REPO_COMMIT"}

About the author

Gary Lewis Cheetham is an automotive marketing specialist, born and raised in Oldham, Greater Manchester. He spent his teenage years working at the family dealership after school, learning the ropes of the car trade from the inside out.

After moving on to working in marketing, Gary Lewis founded GL Digital in 2020 when he noticed a need for direct-to-consumer marketing platforms within the auto industry. He now strives every day to help independent dealers in the UK and US realise their potential. Gary also loves Formula 1 and motorsport.

More Articles

SEO For Car Dealerships: Everything You Need to Know

SEO For Car Dealerships: Everything You Need to Know

We will be the first to say it: SEO for car dealerships is officially over in 2022. Car dealers fail at SEO time and time again, because…

5 minute read - 07/02/2022

Everything you need to know about Conversion Rate Optimisation for Car dealerships in 2022

Everything you need to know about Conversion Rate Optimisation for Car dealerships in 2022

This article will cover how dealerships can do conversion rate optimisation on their website and sales funnels, including for lead…

6 minute read - 27/01/2022

How to run successful Email Marketing for Car Dealerships in 2022

How to run successful Email Marketing for Car Dealerships in 2022

Email marketing is one of the most effective digital marketing strategies for car dealerships to build relationships with customers. It…

5 minute read - 27/01/2022

See More