首页 > 解决方案 > Azure 构建管道 - 在模板中使用“DownloadSecureFile”任务

问题描述

我有一个 Azure DevOps 项目,其中包含几个 YAML 构建管道,它们为某些任务共享一个通用模板。

我现在想DownloadSecureFile向该模板添加一个任务,但我找不到让它工作的方法。以下代码段在添加到模板时会导致错误,但在父管道定义中可以正常工作(假设我还将${{ xx }}变量名称的语法替换为$(xx)版本):

- 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

错误发生在“提取文件”步骤并且是Input required: archiveFilePatterns,所以看起来它只是没有找到变量。

作为一种解决方法,我可以将下载任务移动到父管道脚本并将文件路径作为参数传递。但是,这意味着复制任务,这似乎有点像 hack。

标签: azure-devopsazure-pipelines

解决方案


美元双花括号中的变量在模板扩展时解析。它们不是任务的输出。

任务的输出变量由美元单括号引用,它们不需要以“变量”一词开头。

所以我相信你要找的线是这样的,它不受模板机制的影响。

    archiveFilePatterns: $(securezip.secureFilePath)

推荐阅读