TeamCity
  • 2 Minutes to read
  • Dark
    Light
  • PDF

TeamCity

  • Dark
    Light
  • PDF

Article Summary

With the Stackify Retrace Deployment Recorder plugin for TeamCity you can notify Retrace of a deployment with a custom build step. This will allow you to pass in TeamCity Environment variables with ease when notifying Retrace.

You can view the plugin on Jetbrain's site here: Stackify Retrace Deployment Recorder

Using the TeamCity Plugin

  1. When viewing a build click "Edit Configuration Settings"

  1. Navigate to Build Steps > Click Add build step

  1. Choose "Stackify Retrace Deployment Recorder" from the dropdown.

Note: You will see some default values already filled in for some of the parameters. These are suggestions that use TeamCity Environment Variables as well as some Custom Build Parameters that are outlined here.

  1. Your App Name needs to match the name of an App within Retrace

  1. Click Save

Alternative: Create a Manual Build Step

Instead of using our plugin, you can also manually add a build step in TeamCity.

Add a Build Step

From your build configuration where you would like to notify Retrace of your Deployment, for example after a successful deployment, add a build step.

For the Runner Type choose Powershell or Command Line depending on the capabilities for your build agent.

Configure Script

To see the generic examples for Bash and Powershell reference our API Code Samples guide.

Windows Powershell

Select "Powershell" for the Runner Type and we will run the script from Source Code. Enter the script below into the Source Code Content and execute from an external file. You will need to specify the Action type for you Deployment Request (Start, Complete, or Cancel) as well.  

You can overwrite any preset parameters by passing in a Script argument

Add the script below to the Powershell script content.

Param(
                $action = 'complete',
                $apiKey = '%system.Stackify.ApiKey%',        
                $version = '%build.number%',        
                $app = '%Stackify.AppName%',        
                $env = '%env.Stackify_Environment%',        
                $name = 'env.TEAMCITY\_PROJECT\_NAME',                
                $uri = '%vcsroot.url%',        
                $branch = '%vcsroot.branch%',        
                $commit = '%build.vcs.number%',        
                $hostApi        
        )
        
        # build the post url        
        if (!$hostApi) { $hostApi= 'https://api.stackify.net' }        
        $post = $hostApi.TrimEnd('/') + '/api/v1/deployments/' + $action
        
        # build the authorization header        
        $headers = @{'authorization'='ApiKey ' + $apiKey}
        
        # build the body of the post        
        if (!$name) { $name = $version }        
        $bodyObj = @{ Version=$version; AppName=$app; EnvironmentName=$env; }
        
        if ($action -eq "start" -or $action -eq "complete"){        
                $bodyObj.Name = $name        
                if ($uri) { $bodyObj.Uri = $uri }        
                if ($branch) { $bodyObj.Branch = $branch }        
                if ($commit) { $bodyObj.Commit = $commit }
        }
        
        $body = ConvertTo-Json $bodyObj
        
        # send the request        
        Invoke-WebRequest -Uri $post -Method POST -ContentType "application/json" -Headers $headers -Body $body

Linux Bash

Select "Command Line" as your Runner Type and choose to run a custom command.

Paste the script below in the custom script content:

curl -X POST https://api.stackify.net/api/v1/deployments/complete 
-H 'authorization: ApiKey %system.Stackify.ApiKey%' 
-H 'content-type: application/json' 
-d '{
    "Name": "%env.TEAMCITY_PROJECT_NAME%", 
    "Branch": "%vcsroot.branch%", 
    "Commit": "%build.vcs.number%",
    "Version": "%build.number%", 
    "AppName": "%Stackify.AppName%", 
    "EnvironmentName": "%env.Stackify_Environment%"
    }'

Set Variables

Any parameter can be injected into the scripts above using the %parameter.name% syntax.

Setting the ApiKey value at your Root project will allow it to be inherited by all other projects.


Was this article helpful?