0

I'm building a multi-stage pipeline in which my build stage stores a single file as a pipeline artifact. In the deployment stage the artifact is automatically download and I need the name of the file in order to proceed with the following steps.

Currently, I'm publishing as a variable the name of the file stored as the artifact of the build. I'm wondering if the download task would be able to provide the name of the file so that I can further decouple the build and deploy stages.

This is what I'm using right now:

    - bash: |
        jarFile=`ls -1 *.jar`
        echo "##vso[task.setvariable variable=jarFile;isOutput=true]${jarFile}"
      workingDirectory: target
      name: mavenTarget
      displayName: Finds name of built `.jar` file

And then in the deployment stage:

variables:
    - name: jarFile
      value: $[ stageDependencies.ci.build.outputs['mavenTarget.jarFile'] ]
lpacheco
  • 976
  • 1
  • 14
  • 27
  • Could you please provide more details, does your code work? if not, what is the symptome ? At least, it seems that the syntax is good as per [official example](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops), it would be nice if you can provide the full code without sensitive information of course. – Xiang ZHU Aug 14 '22 at 20:05
  • The code I posted works, I'm just wondering if I'm overcomplicating things since a few pipeline tasks already set useful output variables. `DownloadSecureFile` exports a `secureFile` property, for example. If `download` gave me the name of the downloaded artifact I could eliminate a dependence between stages. – lpacheco Aug 16 '22 at 21:55

1 Answers1

1

I'm wondering if the download task would be able to provide the name of the file so that I can further decouple the build and deploy stages.

I am afraid that the Download build artifacts task has no built-in output variable that can represent the name of an artifact or the files in the Artifact.

The output variable of the download artifacts task is XXX.buildnumber. It doesn't contain the info about Artifacts Name or the files in Artifacts.

enter image description here

The cross-stage variables used in your Current YAML is an efficient way. You can continue to use the method.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28