0

I'm having userName and passWord field in my Azure DevOps Variable group, and I would like to pass the userName and passWord to my python script as a command line argument, I'm able to get the userName without any issue but passWord is not coming when I pass it from my pipeline script. I tried printing using echo - its printing empty - not evening printing masked value like this '*****'

Please find my pipeline code below:

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])

I'm getting the below error:

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
Dave Brady
  • 193
  • 9

1 Answers1

1

Secret variables are not automatically exposed as env variables. You have to explicitly map them: Reference secret variables in variable groups. In this case, it would be:

          - task: Bash@3
            displayName: Test variable
            inputs:
              targetType: inline
              env:
                MAPPED_PASSWORD: $(MY_PASSWORD)
              script: |
                echo "hello variables"
                echo $USER_NAME
                echo $MAPPED_PASSWORD 
qbik
  • 5,502
  • 2
  • 27
  • 33