作为一种解决方法,您可以通过rest api编写脚本来判断包视图。如果存在名为 的视图Prerelease
,请将condition
变量设置为true
。
GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/Feeds/{feedId}/Packages/{packageId}/versions/{packageVersionId}?api-version=6.0-preview.1
示例脚本:
$url = 'GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/Feeds/{feedId}/Packages/{packageId}/versions/{packageVersionId}?api-version=6.0-preview.1';
$token = "PAT"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
$results = $response.views.name
foreach($view in $response.views){
if($view.name -eq "Prerelease"){
$condition = "true"
}
}
Write-Host "results = $($results | ConvertTo-Json -Depth 100)"
Write-Host "result = $condition"
然后你可以像这样设置自定义条件eq($(condition), true)
。
第二种解决方法:
添加多个工件源,然后我们指定 Source 别名,如下所示:
我们可以使用Release.TriggeringArtifact.Alias
默认变量来获取条件中触发释放的工件的别名来判断视图。
例如:condition: contains(variables['Release.TriggeringArtifact.Alias'], '@prerelease' ))