Azure管道秘密变量不适用于PR触发器

时间:2019-06-25 04:02:34

标签: azure azure-devops azure-pipelines

我有一个带有秘密变量的天蓝色管道,该秘密变量在上拉请求时触发。触发后,秘密变量对管道不可用。

秘密变量在提交到分支时触发。

管道

successObservable

Secret variable added via the webUI

输出和错误

pr:
  branches:
    include:
    - '*'
trigger:
  branches:
    exclude:
    - '*'

jobs:
- job:
  pool:
    vmImage: 'ubuntu-latest'
  timeoutInMinutes: 360
  displayName: 'Running test'
  steps:
  - bash: |
      if [ -z "$(system.pullRequest.sourceRepositoryUri)" ]
      then
        python3 runTest.py \
          --config "blessedImageConfig-temp.json" \
          --code $(SecretCode)
      else
        python3 runTest.py \
          --config "blessedImageConfig-temp.json" \
          --pullRepo $(system.pullRequest.sourceRepositoryUri) \
          --pullId $(system.pullRequest.pullRequestNumber) \
          --code $(SecretCode)
      fi

1 个答案:

答案 0 :(得分:1)

  

SecretCode:找不到命令

此错误是由一个秘密变量引起的,并且已以错误的方式在命令行中传递。

您可能对此感到困惑。但是,实际上,微软曾经用doc对此发出警告:从不在命令行上传递秘密。这是设计使然。

我曾经在docker build上遇到过类似的问题。我通过将secrets变量值映射到环境变量来解决它,该问题也在Variable的文档中提到。

对于您的 Bash 任务,还有关于秘密变量的解决方案:使用输入的环境变量将秘密变量传递给此脚本',并设置targetType ==内联是必需的

因此,您可以将以下脚本添加到 Bash任务脚本中,以将secret变量映射到环境变量中:

inputs:
    targetType: 'inline'
    - script: 
      echo $code 
      env: 
        code: $(SecretCode)
相关问题