Is it possible to conditionally set the artifact name in my Azure DevOps build pipeline "publish artifact" task?

GregH

I was wondering if it is possible to conditionally set the name of my build artifact in my Azure DevOps build pipeline "publish artifact" task? I want to produce different artifacts based on the input to my build pipeline. Say, based on the input pipeline variables, I want to produce one of three artifacts ("red", "blue", "green"). Is it possible to specify the artifact being produced in my "publish artifact" task based on the input variable, or is it easier/better just to produce three build pipelines?

Leo Liu-MSFT

Is it possible to conditionally set the artifact name in my Azure DevOps build pipeline “publish artifact” task?

I am afraid there is no such out of box way to do that. If you want to conditionally set the artifact name, we have to use the nested variables in the pipeline.

However, At this moment, the value of nested variables (like $(CustomArtifactName_$(Build.SourceBranchName))) are not yet supported in the build pipelines.

As workaround, you could add a Run Inline Powershell task to set the variable based on the input pipeline variables.

In my side, I use Build_SourceBranchName as input pipeline variables. Then I add following scripts in the Inline Powershell task:

- task: InlinePowershell@1
  displayName: 'Inline Powershell'
  inputs:
    Script:

     $branch = $Env:Build_SourceBranchName

     if ($branch -eq "TestA5")
     {
       Write-Host "##vso[task.setvariable variable=CustomArtifactName]Red"
     }
     else
     {
       Write-Host "##vso[task.setvariable variable=CustomArtifactName]Blue"
     }

Then in the Publish Build Artifacts task, I set the ArtifactName with drop-$(CustomArtifactName)

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    ArtifactName: 'drop-$(CustomArtifactName)'

enter image description here

Hope this helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Azure Pipeline Publish Artifact - Artifact Name

How to refer previous task and stop the build in azure devops if there is no new data to publish an artifact

Download and publish artifact only if exist in azure pipeline

How to publish artifact into Azure Artifact

TFS 2015: Publish artifact - "A task was canceled"

Why isn't my VSTS "Publish Artifact" task picking up my published folder?

Not possible to publish artifact to shared location in TFS

yml pipeline: publish artifact with code from multiple repositories

What is the difference between Copy Files vs Publish Artifact task in VSTS?

What is this cryptic artifact name created by the Publish Symbols Azure DevOps task?

Release is triggered even though build does not publish artifact

VSTS Build agent issues in step 'Publish Artifact: drop'

Create a zip archive via Google Cloud Build step to publish it as an artifact

Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline?

TFS online Publish artifact

How to set Pipeline 'Task version' in YAML in Azure Devops pipeline

How to create a change set from build pipeline in Azure DevOps to push some file into my repository

How to copy an Azure DevOps build artifact to a Docker image build in the same pipeline?

Set Xcode version in Azure DevOps pipeline in CmdLine@2 task

Set App Settings for Visual Studio Test Task in Azure DevOps Pipeline

Is it possible to download files during the build pipeline on Azure DevOps?

TFS 2015 U1 vNext build Publish Artifact always fails with Unable to associate artifact with resource

Azure DevOps yaml pipeline, downloaded artifact is empty

Artifact not being downloaded in release pipeline - Azure DevOps

File pattern for Publish Pipeline Artifact in Azure DevOps

Azure DevOps pipeline build name based on branch of different repository

Publish Artifact with <scope>test</scope>

failed to publish artifact with JFrog CLI

Publish latest build artifact from "LOCAL" Jenkins to Azure DevOps Release Pipeline?