ADO how to read build information from python script started from ADO-agent
Question:
I am building a pipeline in Azure Devops. I have a Yaml file which is starting a python script on a self-hosted agent. 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?
The information i need is information as:
build.definitionName,
system.teamProjectId,
system.pipelineStartTime
Answers:
Python can access these variables using 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:
import os
os.environ['BUILD_DEFINITIONNAME']
os.environ['SYSTEM_TEAMPROJECTID']
os.environ['SYSTEM_PIPELINESTARTTIME']
I am building a pipeline in Azure Devops. I have a Yaml file which is starting a python script on a self-hosted agent. 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?
The information i need is information as:
build.definitionName,
system.teamProjectId,
system.pipelineStartTime
Python can access these variables using 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:
import os
os.environ['BUILD_DEFINITIONNAME']
os.environ['SYSTEM_TEAMPROJECTID']
os.environ['SYSTEM_PIPELINESTARTTIME']