从 AzureDevOps 发布任务让 key 轮换适用于 Azure 存储帐户的最简单方法是什么?当前的计划是在发布后重新生成旧 key 以使其失效,并拥有一个可以在下次部署时使用的新 key 。但是为了让它工作,似乎我至少需要存储 key 的名称以在发布变量中使用。
我查看了他的日志记录任务( https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md ),但这只会更改当前版本中的值,而不会修改版本定义。
最佳答案
您可以使用 REST API ( Definitions - Update ) 从发布任务更新发布定义变量的值。
Agent Phase
并选择 Allow Scripts to Access OAuth Token
.见 Use the OAuth token to access the REST API Project Collection Build Service (xxx)
帐户编辑释放管道权限。 (选择发布管道 -->
...
--> Security
--> Edit release definition
设置为 Allow
)v1030
的值)$url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)$env:SYSTEM_TEAMPROJECTID/_apis/Release/definitions/$($env:RELEASE_DEFINITIONID)?api-version=5.0-preview.3"
Write-Host "URL: $url"
$pipeline = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
# Update an existing variable named v1030 to its new value 1035
$pipeline.variables.v1030.value = "1035"
####****************** update the modified object **************************
$json = @($pipeline) | ConvertTo-Json -Depth 99
$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
write-host "=========================================================="
Write-host "The value of Varialbe 'v1030' is updated to" $updatedef.variables.v1030.value
write-host "=========================================================="
关于azure-devops - 如何从发布任务修改 Azure DevOps 发布定义变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53042605/