Azure DevOps 变量组密码不起作用

Azure DevOps Variable Groups Password not working

我的 Azure DevOps Variable group, 中有用户名和密码字段,我想将用户名和密码作为命令行参数,我能够毫无问题地获取用户名,但是当我从我的管道脚本传递它时,密码没有出现。我尝试使用 echo 进行打印 - 它打印为空 - 而不是像这样 '*****'

晚上打印屏蔽值

请在下面找到我的管道代码:

trigger:
  - none

variables:
    - group: myVariableGrp

pool:
  name: myAgents

stages:
  - stage: Testing
    jobs:
      - job: Test
        displayName: Test script
        steps:
          - task: Bash@3
            displayName: Test variable
            inputs:
              targetType: inline
              script: |
                echo "hello variables"
                echo $USER_NAME
                echo $MY_PASSWORD 

          - task: CmdLine@2
            displayName: Test Python script
            inputs:
              script: python test.py $USER_NAME $MY_PASSWORD

test.py

import sys

# total arguments
#n = len(sys.argv)
#print("Total arguments passed:", n)
print("UserName:", sys.argv[1])
print("Password:", sys.argv[2])

我收到以下错误:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print("Password:", sys.argv[2])
IndexError: list index out of range
##[error]Bash exited with code '1'.
Finishing: Test Python script

秘密变量不会自动公开为环境变量。您必须明确映射它们:Reference secret variables in variable groups。 在这种情况下,它将是:

          - task: Bash@3
            displayName: Test variable
            inputs:
              targetType: inline
              env:
                MAPPED_PASSWORD: $(MY_PASSWORD)
              script: |
                echo "hello variables"
                echo $USER_NAME
                echo $MAPPED_PASSWORD