简体   繁体   English

如何使用 Python 脚本在执行期间读取 Jenkins 管道控制台输出?

[英]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.

相关问题 如何在Python脚本中获取和打印Jenkins控制台输出 - How to get and print Jenkins console output in Python script Jenkins 不在控制台中打印 python 脚本的输出 - Jenkins not printing output of python script in console 如何使用 python 在 shell 中读取控制台 output? - how to read console output in shell using python? 如何在执行Python脚本期间检测文本文件的更改? - How Can I Detect Changes To A Text File During The Execution Of A Python Script? 使用 Jenkins 参数化管道执行 python 脚本 - Executing python script using Jenkins parameterized pipeline 使用 Windows 在 Jenkins 管道中运行 Python 脚本 - Run a Python script in Jenkins Pipeline using Windows 如何使用 Spyder 中的 IPython 控制台运行 python 脚本? - How can I run a python script using the IPython console in Spyder? 如何在Jenkins奴隶的脚本控制台中使用groovy运行python命令? - How to run python commands using groovy in Jenkins slaves' Script Console? 如何从我的qt项目中获取脚本(python)的路径,以便可以在执行过程中运行它? - How do I get the path of a script(python) from my qt project, so I can run it during execution? 我正在尝试在Jenkins上使用python slaves运行管道,但不知何故它总是显示此输出:jenkins没有标签&#39;python&#39; - I'm trying to run a pipeline using python slaves on Jenkins but somehow it's always shows this output : jenkins doesn't have label 'python'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM