Pin TeamCity Build Version and Dependencies

Octopus.Script exported 2016-05-06 by roberto-mardeni belongs to ‘TeamCity’ category.

Try to pin 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:8082

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 Pin Comment

TeamCityPinComment

Comments for the TeamCity Pin

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']
$tcComments = $OctopusParameters['TeamCityPinComment']
$tcTags = $OctopusParameters['TeamCityTags']

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

[string]$restUri = $tcUrl + ("/httpAuth/app/rest/builds/?locator=buildType:{1},branch:default:any,number:{0}" -f $buildNumber,$buildTypeId)

$response = Invoke-RestMethod -Headers $headers -DisableKeepAlive -Method GET -Uri $restUri

if ($response -ne $null -and $response.builds.count -eq 1) {
    $id = $response.builds.build.id
    
    [string]$pinUri = $tcUrl + ("/ajax.html?pinComment={1}&pin=true&buildId={0}&buildTagsInfo={2}&applyToChainBuilds=true" -f $id,$tcComments,$tcTags)

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

    try {
        Invoke-RestMethod -Headers $headers -DisableKeepAlive -Method POST -Uri $pinUri
        Write-Output "Build ID $($id) pinned successfully"
    } catch {
        Write-Output "Build ID $($id) not pinned: $($_.Exception.Message)"
    }
} else {
    Write-Warning "Build not found, unable to pin"
}

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": "35d1aae8-950a-466e-99f7-afd8fa9d5dff",
  "Name": "Pin TeamCity Build Version and Dependencies",
  "Description": "Try to pin the TeamCity build version and dependencies\n(Requires Octopus version to match TeamCity version)",
  "Version": 1,
  "ExportedAt": "2016-05-06T17:36:39.661+00:00",
  "ActionType": "Octopus.Script",
  "Author": "roberto-mardeni",
  "Parameters": [
    {
      "Name": "buildNumber",
      "Label": "Build Number",
      "HelpText": null,
      "DefaultValue": "#{Octopus.Release.Number}",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "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": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "TeamCityUrl",
      "Label": "Url of TeamCity Server",
      "HelpText": "The url to the TeamCity server.",
      "DefaultValue": "http://localhost:8082",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "TeamCityUser",
      "Label": "TeamCity User",
      "HelpText": "The TeamCity user used for pinning the build",
      "DefaultValue": "teamcity",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "TeamCityPassword",
      "Label": "TeamCity User Password",
      "HelpText": "The password for the TeamCity user.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Name": "TeamCityPinComment",
      "Label": "TeamCity Pin Comment",
      "HelpText": "Comments for the TeamCity Pin",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "TeamCityTags",
      "Label": "TeamCity Tags",
      "HelpText": "Tags to add to the TeamCity Build, space separated list of values.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "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$tcComments = $OctopusParameters['TeamCityPinComment']\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]$restUri = $tcUrl + (\"/httpAuth/app/rest/builds/?locator=buildType:{1},branch:default:any,number:{0}\" -f $buildNumber,$buildTypeId)\n\n$response = Invoke-RestMethod -Headers $headers -DisableKeepAlive -Method GET -Uri $restUri\n\nif ($response -ne $null -and $response.builds.count -eq 1) {\n    $id = $response.builds.build.id\n    \n    [string]$pinUri = $tcUrl + (\"/ajax.html?pinComment={1}&pin=true&buildId={0}&buildTagsInfo={2}&applyToChainBuilds=true\" -f $id,$tcComments,$tcTags)\n\n    Write-Output \"Pinning Build with ID $($id)\"\n\n    try {\n        Invoke-RestMethod -Headers $headers -DisableKeepAlive -Method POST -Uri $pinUri\n        Write-Output \"Build ID $($id) pinned successfully\"\n    } catch {\n        Write-Output \"Build ID $($id) not pinned: $($_.Exception.Message)\"\n    }\n} else {\n    Write-Warning \"Build not found, unable to pin\"\n}\n",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "Category": "TeamCity",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/teamcity-pin-build-and-dependencies.json",
  "Website": "/step-templates/35d1aae8-950a-466e-99f7-afd8fa9d5dff",
  "Logo": "iVBORw0KGgoAAAAN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