I'm using a Python script task of type 'file' in my Azure DevOps Yaml pipeline. I need to use the variables that I defined in my Variable Group in the Python file. The following is my task on Azure devops yaml pipeline.
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptPath: 'pythonTest.py'
Any advise on how I can achieve this?
Thanks!
You need to pass the variables to the script, using arguments, and you of course need to reference the variable group:
variables:
- group: variableGroup
steps:
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptPath: 'pythonTest.py'
arguments: --variableInScript $(variableInVariableGroup)
And then use 'argparse' in the script.
If you were using an inline script you could have done it like this:
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
print('variableInVariableGroup: $(variableInVariableGroup)')