【发布时间】:2021-02-15 20:22:24
【问题描述】:
我想在阶段运行时更新发布(不是发布定义)范围变量的值,但每次我尝试都会收到以下错误消息。
请问我该怎么做?
##[error]Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402898: Stage 'dev' cannot be modified as it is
in-progress or completed. Changes were detected in the following properties:
'Variables'","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Mic
rosoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
At line:263 char:5
+ Invoke-RestMethod -Uri $url -Method Put -ContentType "application ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
2020-11-03T06:45:48.2096034Z ##[error]PowerShell exited with code '1'.
示例脚本:
$url = "{0}{1}/_apis/Release/releases/{2}?api-version=5.0" -f $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI, $env:SYSTEM_TEAMPROJECTID, $env:RELEASE_RELEASEID
$pipeline = Invoke-RestMethod -Uri $url -Method Get -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
# Update an existing scoped variable named TestVar
# Just for StackOverflow we assume that the currently running stage in Azure DevOps Server
# matches this environment[0] below
$pipeline.environments[0].variables.TestVar.value = "NewValue"
$body = $pipeline | ConvertTo-Json -Depth 99
Invoke-RestMethod -Uri $url -Method Put -Body $body-ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
以防万一还有另一种解决方案...我想要实现的是稍后在单独的“替代文件”JSON 转换步骤中使用 PowerShell 脚本的变量输出来填充其中的值Web 应用程序的 appsettings.json 文件。问题是该变量是在一项作业中创建的,并且没有被 Substitute Files 步骤使用,因为我认为它需要是一个发布变量,而不仅仅是任务变量。
【问题讨论】:
标签: azure-devops azure-pipelines azure-devops-rest-api azure-devops-server-2019