我想获取发布开始日期或构建日期,并在我的部署应用程序中使用此日期字符串,但是我没有在预定义变量Wiki https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch
中找到它有人知道如何获得它吗?还是不存在日期的预定义变量?
答案 0 :(得分:2)
您始终可以使用rest api获得完整的信息:Get Release
获取创建日期和时间的小示例:
添加以下powershell内联脚本来更新您的变量。
$user = ""
$token = "$(System.AccessToken)"
$teamProject = "$(System.TeamProject)"
$releaseId = "$(Release.ReleaseId)"
$orgUrl = "$(System.CollectionUri)"
$orgUrlrel = $orgUrl -replace "dev", "vsrm.dev"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uriGetRelease = "$orgUrlrel/$teamProject/_apis/release/releases/$releaseId"+"?api-version=5.1"
$resultStatus = Invoke-RestMethod -Uri $uriGetRelease -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
[datetime]$releaseDate = $resultStatus.createdOn
$setDateTimeVar = "##vso[task.setvariable variable=rl.CreatedDateTime]" + $releaseDate
Write-Host $setDateTimeVar
答案 1 :(得分:0)