[英]How can i read Jenkins pipeline console output during execution using Python Script?
I have a requirement to read the console output of a previous stage(of the pipeline) during the pipeline execution.我需要在管道执行期间读取前一阶段(管道的)的控制台输出。 The console output from previous stage will be input to a python script, which i am running in the next stage.
上一阶段的控制台输出将输入到我在下一阶段运行的 python 脚本中。 Please suggest
请建议
If you use Blue Ocean Plugin, you can retrieve stage-wise console output using Blue Ocean REST API .如果您使用 Blue Ocean 插件,则可以使用Blue Ocean REST API检索阶段式控制台输出。
A stage in Blue Ocean URL is denoted by a node number when you click that stage.当您单击该阶段时,Blue Ocean URL 中的阶段由节点编号表示。 For example, in the URL
.../blue/organizations/jenkins/<job_name>/detail/<job_name>/<build_number>/pipeline/24
, the node number is 24
.例如,在 URL
.../blue/organizations/jenkins/<job_name>/detail/<job_name>/<build_number>/pipeline/24
,节点编号为24
。 This value remains constant for a specific stage in a given pipeline.对于给定管道中的特定阶段,该值保持不变。
Assuming your job has anonymous read permissions, in your downstream pipeline stage you can call a Python script to read the console output of any previous stage.假设您的作业具有匿名读取权限,在您的下游管道阶段,您可以调用 Python 脚本来读取任何先前阶段的控制台输出。
Sample Python script:示例 Python 脚本:
import os
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
current_build_num = os.environ['BUILD_NUMBER']
stage_url = 'https://<jenkins_base_url>/cdf/blue/rest/organizations/jenkins/pipelines/<job_name>/runs/{0}/nodes/<node_number>/log/'.format(current_build_num)
stage_log = requests.get(stage_url, verify=False).content
print(stage_log)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.