3

From within both Build & Release pipelines in Azure Devops, I'm triggering other pipelines via api.

I am trying to get my release pipeline to harvest custom variables that were discovered / used during the associated build.

I'm able to get a list of builds via get api, and i'm able to spawn other builds and pass parameters to them.

While I can spawn a release via api, I have been unsuccessful in passing parameters... or harvesting parameters on-demand at the time of Create Release.

I have reviewed Microsoft's documentation and successfully queued Builds via api with custom parameters and created releases without custom parameters.

[String]$buildID = "$env:BUILD_BUILDID"
[String]$project = "$env:SYSTEM_TEAMPROJECT"
[String]$projecturi = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"
[String]$alias = "drop"

$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$url= $projecturi + $project + "/_apis/release/releases?api-version=5.0-preview"

$JSON = @"
{
  "definitionId": 9,
  "description": "Testing API Release",
  "artifacts": [
    {
      "alias": "$alias",
      "instanceReference": {
        "id": "$buildID",
        "name": null
      }
    }
  ],
  "isDraft": false,
  "reason": "none",
  "manualEnvironments": null
}
"@

Write-Host $url
$responseRelease = Invoke-RestMethod -Uri $url -headers $headers -Method Post -ContentType "application/json" -Body $JSON

Write-Host $responseRelease

The results of the current code creates a release, but don't pass custom variables (or harvest custom variables from a completed build). I would rather pass or harvest them than recalculate them.

nuprap
  • 385
  • 5
  • 22
  • I'm hoping that there's a way to read-in variables from a build... because I'm assuming that I'm still unable to pass variables into a release based on this link. https://stackoverflow.com/questions/49283685/vsts-rest-api-create-release – nuprap Aug 14 '19 at 18:39

1 Answers1

2

First as you have mentioned in the comment, it's not able to directly change variables when deploy a release. As a user voice on Road map:

Change release variables' value when deploy a release

https://developercommunity.visualstudio.com/idea/365596/change-release-variables-value-when-deploy-a-relea.html.

According to your description, seems you want to access the Build variables from Release definition. This is also not a build-in feature at present.

As a workaround, try to use this 3rd-party Azure DevOps extension Variable Tools for Azure DevOps Services.

In the "build pipeline" you can create a JSON file using "save variables". This file needs to be published as artifact or with existing artifact.

In the "release pipeline" you can restore the variables using "load variables" from the JSON file.

Another way is storing the variable’s value in Variable Group and link the variable group into your release definition.

During release, you can get variable groups firstly, and filter the variable under the variable group-$(Build.BuildId).

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62