What we need to do is create a variable in the release definition and set its scope to “Release”:
Then, for each stage, we need to enable this checkbox in the agent job:
I explain later why we’re enabling this. We now only need to update this variable after uploading the DP to LCS. Add an inline Powershell step after the upload one and do this:
# Populate & store value to update pipeline $assetId= "$(GoldenUpload.FileAssetId)" Write-Output ('##vso[task.setvariable variable=localAsset]{0}' -f $assetId) #region variables $ReleaseVariableName = 'axzfileid' $releaseurl = ('{0}{1}/_apis/release/releases/{2}?api-version=5.0' -f $($env:SYSTEM_TEAMFOUNDATIONSERVERURI), $($env:SYSTEM_TEAMPROJECTID), $($env:RELEASE_RELEASEID) ) #endregion #region Get Release Definition Write-Host "URL: $releaseurl" $Release = Invoke-RestMethod -Uri $releaseurl -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } #endregion #region Output current Release Pipeline #Write-Output ('Release Pipeline variables output: {0}' -f $($Release.variables | #ConvertTo-Json -Depth 10)) #endregion #Update axzfileid with new value $release.variables.($ReleaseVariableName).value = $assetId #region update release pipeline Write-Output ('Updating Release Definition') $json = @($release) | ConvertTo-Json -Depth 99 $enc = [System.Text.Encoding]::UTF8 $json= $enc.GetBytes($json) Invoke-RestMethod -Uri $releaseurl -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } #endregionYou need to change the following:
- Line 2: $assetId= “$(GoldenUpload.FileAssetId)”. Change $(GoldenUpload.FileAssetId) for your output variable name.
- Line 6: $ReleaseVariableName = ‘axzfileid’. Change axzfileid for your Release variable name.