rsch006
rsch006

Reputation: 115

Is it possible to get the Artifact Name in Release?

I have a requirement to get the build artifact name in release? I dont see a predefined release variables which can get this. Is there a way to fetch this?

Upvotes: 5

Views: 8499

Answers (3)

GalacticJello
GalacticJello

Reputation: 11445

This is kind of a hack/kludge, but if you name your Release to be the same as the package you are releasing, you can get the name from the variable

$(Release.DefinitionName)

So if your build creates a package called My.Cool.Package in a build pipeline called my_cool_package, that ends up being aliased in the release pipeline as _my_cool_package.

Naming the Release pipeline the same as the package (My.Cool.Package) allows you to access the package and files within it (for doing XML and JSON transforms for example in other tasks) by using

$(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)/$(Release.DefinitionName)  

Upvotes: 1

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30362

If you mean you want to get the Artifact Name which is defined in Publish Build Artifacts task in Build process (By default it's Drop), then you can run below PowerShell script calling the REST API to retrieve the value and set a variable with logging command. After that you can use the variable in subsequent tasks...

  1. Enable Allow scripts to access the OAuth token in Agent Phase
  2. Add a PowerShell task to run below script

    $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...
    

enter image description here

Upvotes: 5

Daniel Mann
Daniel Mann

Reputation: 58980

This is well-documented under the sections General Artifact Variables and Primary Artifact Variables.

The primary artifact name is Build.DefinitionName.

Upvotes: -2

Related Questions