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

前端 未结 2 583
清歌不尽
清歌不尽 2020-11-30 15:45

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 differen

相关标签:
2条回答
  • 2020-11-30 16:03

    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)'
    

    Hope this helps.

    0 讨论(0)
  • 2020-11-30 16:10

    This is the bash version in case you run the task on Linux. The NAME is a custom variable which uses the pre-defined variable as value.

    trigger_model_version=RELEASE_ARTIFACTS_${NAME^^}_BUILDNUMBER
    export version=${!trigger_model_version}
    echo Deploying ${NAME}:${version}
    
    0 讨论(0)
提交回复
热议问题