是否可以在Release中获取Artifact Name?

rsc*_*006 5 azure azure-devops

我需要在发布中获取构建工件名称吗?我没有看到可以得到这个的预定义发布变量。有办法获取这个吗?

And*_*SFT 5

如果您的意思是您想要获取构建过程Artifact Name中任务中定义的值Publish Build Artifacts(默认情况下为Drop),那么您可以运行下面的 PowerShell 脚本,调用REST API来检索值并使用日志记录命令设置变量。之后您可以在后续任务中使用该变量......

  1. 启用Allow scripts to access the OAuth tokenAgent Phase
  2. 添加 PowerShell 任务来运行下面的脚本

    $url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/$env:BUILD_BUILDID/artifacts?api-version=4.1"
    Write-Host "URL: $url"
    $pipeline = Invoke-RestMethod -Uri $url -Headers @{
        Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
    }
    Write-Host "artifactName:" ($artifactName = $Pipeline.value.name)
    
    #Set Variable $artifactName
    Write-Host "##vso[task.setvariable variable=artifactName]$artifactName"
    
    #Then you can use the variable $artifactName in the subsequent tasks...
    
    Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Dan*_*ann -2

这在General Artifact VariablesPrimary Artifact Variables部分中有详细记录

主要工件名称是Build.DefinitionName