[英]how to get the value of a variable stored in a python script from azure pipeline
目前,我需要在 azure VM 上運行管道,我正在使用 python 腳本來運行一個進程,其中我將 ID 存儲在一個變量中,我需要在代碼 Z6EEDC03A678A69933C2FZD76 中使用該變量值用作參數的管道,有人知道我該怎么做嗎?
在 Python 腳本中,您可以使用要傳遞的值設置 output 變量,以便可以在管道中的后續步驟中訪問它。
在 Python 腳本中,使用日志記錄命令“ SetVariable
”將 output 變量設置為所需的值。 並使用Python 腳本任務運行腳本。
在同一管道作業的后續步驟中,您可以使用表達式“ $({taskName}.{variableName})
”來訪問 output 變量。
下面是一個示例 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.