0
votes

I have Azure DevOps yaml deployment pipelines that trigger when a build pipeline completes and publishes an artifact. According to docs found here, artifacts will be downloaded to

to $(PIPELINE.WORKSPACE)/pipeline-identifier/artifact-identifier folder.

my trigger is similar to

resources:
 pipelines:
 - pipeline: SmartHotel-PipelineIdentifier
   project: DevOpsProject
   source: SmartHotel-CI
   trigger:
     branches:
      include:
      - main

How can i access the pipeline-identifier from a template? I need to be able to create

$(PIPELINE.WORKSPACE)/SmartHotel-PipelineIdentifier/artifact-identifier

based upon the pipeline definition above.

When the pipeline is triggered by a build, I'm able to use

$(Pipeline.Workspace)/$(resources.triggeringAlias)/artifact-identifier

to give me what I need, but that value is blank when the pipeline is triggered manually.

How can I access what appears to be called the pipeline-identifier value for a specific pipeline to be used within templates in the deployment jobs of pipelines?

1

1 Answers

0
votes

You can get various properties of the pipeline resource, but that's all assuming you know the alias. But there's no way to get that alias if it's not triggered automatically. If you had more pipeline resources, how would you know which one to get?

In this case, you could:

  • pass the pipeline identifier (SmartHotel-PipelineIdentifier) as a parameter to the template.

  • assume a convention for well-known pipeline identifiers (i.e. always use artifact-pipeline instead of SmartHotel-PipelineIdentifier)

  • download (or move) the artifact to a well-known location before calling the template. That's assuming you already use the pipeline identifier for the download task anyway, so you could simply do mv $(Pipeline.Workspace)/SmartHotel-PipelineIdentifier/artifact-identifier $(Pipeline.Workspace)/artifact-identifier right after download.

    You can also use the full DownloadPipelineArtifact task (which download is a shorthand for) and configure it to download to a different directory.

  • determine the directory name in runtime, once the artifact is downloaded and set a pipeline variable dynamically:

      # there will be directories in $(Pipeline.Workspace) like "a", "b", "s" for checked out repositories - ignore them
    - pwsh: |
        ls $(Pipeline.Workspace)
        $alias = Get-ChildItem $(Pipeline.Workspace) | ? { $_.Name.Length -gt 1 } | select -ExpandProperty Name -First 1
        echo "##vso[task.setvariable variable=ArtifactAlias]$alias"
      displayName: determine artifact pipeline alias
    - pwsh: echo 'alias: $(ArtifactAlias)' # use $(ArtifactAlias) where you would use $(resources.triggeringAlias)