且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

包括下游/子Jenkins作业的控制台输出到触发作业的控制台输出

更新时间:2023-12-05 12:15:40

有趣。我会尝试这样的。

Interesting. I'd try something like this.

http:// jenkinsurl / job / jobname / lastBuild / api /

访问渐进式控制台输出

您可以检索正在进行的控制台输出使用参数重复GET请求。你基本上会发送GET请求到这个URL(或者这个URL,如果你想要的HTML可以放到标签。)start参数控制字节偏移的开始。

Accessing Progressive Console Output
You can retrieve in-progress console output by making repeated GET requests with a parameter. You'll basically send GET request to this URL (or this URL if you want HTML that can be put into tag.) The start parameter controls the byte offset of where you start.

响应将包含控制台输出的一个块,以及表示原始日志文件的字节偏移量的X-Text-Size标头。这是您要用作下一次调用的开始参数的数字。

The response will contain a chunk of the console output, as well as the X-Text-Size header that represents the bytes offset (of the raw log file). This is the number you want to use as the start parameter for the next call.

如果响应还包含X-More-Data:true标头,则服务器指示构建正在进行中,并且您需要在一段延迟后重复请求。 Jenkins UI在进行下一个调用之前等待5秒钟。当此标题不存在时,您知道您已检索所有数据,并且构建完成。

If the response also contains the X-More-Data: true header, the server is indicating that the build is in progress, and you need to repeat the request after some delay. The Jenkins UI waits 5 seconds before making the next call. When this header is not present, you know that you've retrieved all the data and the build is complete.

下游作业,但不阻塞直到下游完成。而是,添加一个额外的步骤( execute shell ,可能),并编写一个脚本,将读取其他作业的控制台输出,如上所示,并显示在控制台输出当前工作。你将不得不通过寻找 X-More-Data:true 头来检测子作业的完成时间,如上所述。

So you can trigger a downstream job, but don't "block until downstream completes". Instead, add an extra step (execute shell, probably) and write a script that will read the console output of the other job as indicated above, and display it in console output of current job. You will have to detect when the child job finished by looking for X-More-Data: true header, as detailed above.