[英]how to get the value of a variable stored in a python script from azure pipeline
Currently, I am faced with the need to run a pipeline on an azure VM, I am using a python script to run a process in which I store the ID in a variable, and I need to use that variable value in the code yaml from the pipeline to use as a parameter, does anyone know how I can proceed?目前,我需要在 azure VM 上运行管道,我正在使用 python 脚本来运行一个进程,其中我将 ID 存储在一个变量中,我需要在代码 Z6EEDC03A678A69933C2FZD76 中使用该变量值用作参数的管道,有人知道我该怎么做吗?
In your Python script, you can set an output variable with the value you want to pass so that it can be access in the subsequent steps in the pipeline.在 Python 脚本中,您可以使用要传递的值设置 output 变量,以便可以在管道中的后续步骤中访问它。
In the Python script, use the logging command ' SetVariable
' to set an output variable with the value you want.在 Python 脚本中,使用日志记录命令“
SetVariable
”将 output 变量设置为所需的值。 And use the Python Script task to run the script.并使用Python 脚本任务运行脚本。
In the subsequent steps of the same pipeline job, you can use the expression ' $({taskName}.{variableName})
' to access the output variable.在同一管道作业的后续步骤中,您可以使用表达式“
$({taskName}.{variableName})
”来访问 output 变量。
Below is an example YAML pipeline as reference.下面是一个示例 YAML 管道作为参考。
jobs:
- job: job1
displayName: 'Job 1'
pool:
vmImage: ubuntu-latest
steps:
- task: PythonScript@0
name: pythScr
displayName: 'Set output variable'
inputs:
scriptSource: inline
script: |
import subprocess
myID = 123
subprocess.Popen(["echo", "##vso[task.setvariable variable=MY_ID;isoutput=true]{0}".format(myID)])
- task: Bash@3
displayName: 'Print output variable'
inputs:
targetType: inline
script: echo "MY_ID = $(pythScr.MY_ID)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.