Tag TeamCity Build Version

Octopus.Script exported 2018-01-19 by B0R1K belongs to ‘Other’ category.

Try to tag the TeamCity build version and dependencies (Requires Octopus version to match TeamCity version)

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Build Number

buildNumber = #{Octopus.Release.Number}

null

Build Configuration ID

buildTypeId =

The build configuration id to look for the build to pin.

General Settings of the Build Configuration

Url of TeamCity Server

TeamCityUrl = http://localhost:88

The url to the TeamCity server.

TeamCity User

TeamCityUser = teamcity

The TeamCity user used for pinning the build

TeamCity User Password

TeamCityPassword =

The password for the TeamCity user.

TeamCity Tags

TeamCityTags =

Tags to add to the TeamCity Build, space separated list of values.

Script body

Steps based on this template will execute the following PowerShell script.

$buildNumber = $OctopusParameters['buildNumber']
$buildTypeId = $OctopusParameters['buildTypeId']

$tcUrl = $OctopusParameters['TeamCityUrl']
$tcUser = $OctopusParameters['TeamCityUser']
$tcPass = $OctopusParameters['TeamCityPassword']
$tcTags = $OctopusParameters['TeamCityTags']

$credentials = [System.Text.Encoding]::UTF8.GetBytes("$($tcUser):$($tcPass)")
$headers = @{ "Authorization" = "Basic $([System.Convert]::ToBase64String($credentials))" }

[string]$tagUri = $tcUrl + ("/app/rest/builds/buildType:{0},number:{1}/tags/" -f $buildTypeId,$buildNumber)

Write-Output "Tagging Build with ID $($id)"

try {
    Invoke-RestMethod -Headers $headers -DisableKeepAlive -Method POST -Uri $tagUri -Body $tcTags -ContentType "text/plain"
    Write-Output "Build ID $($id) tagged successfully"
} catch {
    Write-Output "Build ID $($id) not tagged: $($_.Exception.Message)"
}


Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "aabf7d20-579f-4e6f-af5f-14e0d87b1258",
  "Name": "Tag TeamCity Build Version",
  "Description": "Try to tag the TeamCity build version and dependencies\n(Requires Octopus version to match TeamCity version)",
  "Version": 2,
  "ExportedAt": "2018-01-19T17:39:44.741Z",
  "ActionType": "Octopus.Script",
  "Author": "B0R1K",
  "Parameters": [
    {
      "Id": "5fa8e5cb-0b93-4d23-8ef3-322b2bbb5e4c",
      "Name": "buildNumber",
      "Label": "Build Number",
      "HelpText": null,
      "DefaultValue": "#{Octopus.Release.Number}",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "6086a3f2-ed02-4066-a497-1b0066178ed0",
      "Name": "buildTypeId",
      "Label": "Build Configuration ID",
      "HelpText": "The build configuration id to look for the build to pin.\n\nGeneral Settings of the Build Configuration",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "2b248891-64ec-48ae-94ed-b0e2d32b4ade",
      "Name": "TeamCityUrl",
      "Label": "Url of TeamCity Server",
      "HelpText": "The url to the TeamCity server.",
      "DefaultValue": "http://localhost:88",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "f736c827-0429-4db5-9f9e-ddfa97d364a8",
      "Name": "TeamCityUser",
      "Label": "TeamCity User",
      "HelpText": "The TeamCity user used for pinning the build",
      "DefaultValue": "teamcity",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "202383fe-c464-4d5c-bad5-7069ee8037fd",
      "Name": "TeamCityPassword",
      "Label": "TeamCity User Password",
      "HelpText": "The password for the TeamCity user.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      },
      "Links": {}
    },
    {
      "Id": "518b4bdf-84e6-4abd-b88a-c1aa457364e0",
      "Name": "TeamCityTags",
      "Label": "TeamCity Tags",
      "HelpText": "Tags to add to the TeamCity Build, space separated list of values.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "$buildNumber = $OctopusParameters['buildNumber']\n$buildTypeId = $OctopusParameters['buildTypeId']\n\n$tcUrl = $OctopusParameters['TeamCityUrl']\n$tcUser = $OctopusParameters['TeamCityUser']\n$tcPass = $OctopusParameters['TeamCityPassword']\n$tcTags = $OctopusParameters['TeamCityTags']\n\n$credentials = [System.Text.Encoding]::UTF8.GetBytes(\"$($tcUser):$($tcPass)\")\n$headers = @{ \"Authorization\" = \"Basic $([System.Convert]::ToBase64String($credentials))\" }\n\n[string]$tagUri = $tcUrl + (\"/app/rest/builds/buildType:{0},number:{1}/tags/\" -f $buildTypeId,$buildNumber)\n\nWrite-Output \"Tagging Build with ID $($id)\"\n\ntry {\n    Invoke-RestMethod -Headers $headers -DisableKeepAlive -Method POST -Uri $tagUri -Body $tcTags -ContentType \"text/plain\"\n    Write-Output \"Build ID $($id) tagged successfully\"\n} catch {\n    Write-Output \"Build ID $($id) not tagged: $($_.Exception.Message)\"\n}\n\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Category": "Other",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/teamcity-tag-build.json",
  "Website": "/step-templates/aabf7d20-579f-4e6f-af5f-14e0d87b1258",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAET9JREFUeNrsnV2MG1cVx2fGH2t7vU6zm27TTdxNgCTbVkUKggBFDR9FIKoWVX2o1BeeqNQXHnjgueozD7z2CSQEQgKEqlIVgSjQlrYQWoHaom6a0u7GyWbrxrus159je8zfvonZ2p7xx5w7c2d8/opWG9vruXPu755z7sfcq7fbbY3FopbOY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