0
votes

I have an Azure DevOps project with a couple of YAML build pipelines that share a common template for some of their tasks.

I now want to add a DownloadSecureFile task to that template, but I can't find a way to get it to work. The following snippet results in an error when added to the template, but works fine in the parent pipeline definition (Assuming I also replace the ${{ xx }} syntax for the variable names with the $(xx) version):

- task: DownloadSecureFile@1
  name: securezip
  displayName: Download latest files
  inputs:
    secureFile: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    retryCount: 5
  
- task: ExtractFiles@1
  displayName: Extract files
  inputs:
    archiveFilePatterns: ${{ variables.securezip.secureFilePath }}
    destinationFolder: '${{ parameters.sourcesDir }}\secure\'
    cleanDestinationFolder: true

The error occurs on the 'Extract File' step and is Input required: archiveFilePatterns, so it looks like it's just not finding the variable.

As a workaround, I could move the download task to the parent pipeline scripts and pass the file path as a parameter. However, that means duplicating the task, which seems like a bit of a hack.

1
I'm a little confused. Is the problem that DownloadSecureFile is failing, as stated? Or is the problem that the following ExtractFiles step is failing? - catfood
The DownloadSecureFile task is working. I just can't seem to access the variable that holds the location of the downloaded file. - Steve
Okay, I cringe to ask this, but have you defined securezip as a variable in the template? I wonder if you're defining a task variable but trying to reference a template variable and those aren't the same thing. - catfood
I can't help noticing that in your question you're naming the first task scurezip (with one E) but accessing a variable called securezip (with two Es) in the second task. - catfood
Ah, that's a typo, the name in the script isn't actually securezip. I have checked the spelling of the real variables though and it's correct. - Steve

1 Answers

1
votes

Variables in dollar-double-curly-brackets are resolved at template expansion time. They are not the output of tasks.

Output variables from tasks are referenced by dollar-single-parentheses and they don't need to start with the word "variables."

So I believe the line you're looking for is like this, and it isn't affected by the template mechanism.

    archiveFilePatterns: $(securezip.secureFilePath)