简体   繁体   English

ADO 如何从 ADO-agent 启动的 python 脚本读取构建信息

[英]ADO how to read build information from python script started from ADO-agent

I am building a pipeline in Azure Devops.我正在 Azure Devops 中构建管道。 I have a Yaml file which is starting a python script on a self-hosted agent.我有一个 Yaml 文件,它正在自托管代理上启动 python 脚本。 Is there any way for me to read information about the pipeline which started the python script inside of the python script without sending it as arguments?有什么方法可以让我阅读有关在 python 脚本内部启动 python 脚本的管道的信息,而不将其作为 arguments 发送?

The information i need is information as:我需要的信息是:

build.definitionName, 
system.teamProjectId, 
system.pipelineStartTime

Python can access these variables using os.environ['Name']. Python 可以使用 os.environ['Name'] 访问这些变量。 As per the documentation , predefined variables are converted into uppercase and any '.'根据文档,预定义变量被转换为大写字母和任何“。” are replace with '_'替换为“_”

For example, to access these variables on a windows OS it should be as simple as:例如,要在 windows 操作系统上访问这些变量,应该很简单:

import os
os.environ['BUILD_DEFINITIONNAME']
os.environ['SYSTEM_TEAMPROJECTID']
os.environ['SYSTEM_PIPELINESTARTTIME']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM