从 Azure DevOps Yaml 管道中 Python 脚本任务中的变量组访问变量
Access variables from Variable Groups inside Python script task in Azure DevOps Yaml pipeline
我在我的 Azure DevOps Yaml 管道中使用类型为 'file' 的 Python 脚本任务。我需要使用我在 Python 文件中的变量组中定义的变量。
以下是我在 Azure devops yaml 管道上的任务。
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptPath: 'pythonTest.py'
关于如何实现这一点有什么建议吗?
谢谢!
您需要使用参数将变量传递给脚本,当然您还需要引用变量组:
variables:
- group: variableGroup
steps:
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptPath: 'pythonTest.py'
arguments: --variableInScript $(variableInVariableGroup)
然后在脚本中使用'argparse'。
如果您使用的是内联脚本,您可以这样做:
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
print('variableInVariableGroup: $(variableInVariableGroup)')
我在我的 Azure DevOps Yaml 管道中使用类型为 'file' 的 Python 脚本任务。我需要使用我在 Python 文件中的变量组中定义的变量。 以下是我在 Azure devops yaml 管道上的任务。
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptPath: 'pythonTest.py'
关于如何实现这一点有什么建议吗?
谢谢!
您需要使用参数将变量传递给脚本,当然您还需要引用变量组:
variables:
- group: variableGroup
steps:
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptPath: 'pythonTest.py'
arguments: --variableInScript $(variableInVariableGroup)
然后在脚本中使用'argparse'。
如果您使用的是内联脚本,您可以这样做:
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
print('variableInVariableGroup: $(variableInVariableGroup)')