Jenkins - 在构建步骤期间检索完整的控制台输出 [英] Jenkins - retrieve full console output during build step

查看:7280
本文介绍了Jenkins - 在构建步骤期间检索完整的控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在互联网上搜索数天,我遇到类似这个的问题。



我需要以原始(plain)文本检索控制台输出。但如果我可以得到它的HTML也很好,我可以解析它。唯一的是我需要在构建步骤中获取它,这是一个问题,因为它应该可用的位置被截断...



我尝试从以下URL(相对于作业)检索控制台输出:




  • / consoleText

  • / logText / progressiveText

  • / logText / progressiveHTML



两个文本是纯文本,不是为了截断,同样适用于HTML一个...正是我需要的 - 只有截断的....



我相信它是可以检索的信息不知何故,因为当查看 / consoleFull 时,会有控制台的实时更新,而不会截断或缓冲。



但是,在检查网页,而不是找到我想要的内容,我发现这个代码,它应该是(我没有包括完整的网页代码,因为它将是大多数不相关的,我相信那些回答能够找出并知道自己应该有什么)

  new Ajax.Request(href,{
方法:post,
参数:{start:e.fetchedBytes},
requestHeaders:headers,
onComplete:function(rsp,_){

var stickToBottom = scroller.isSticking();
var text = rsp.responseText;
if(text!=){
var p = document.createElement(DIV);
e.appendChild(p); //需要第一个为IE
//对于IE使用outerHTML解决方法:
// http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
if(p.outerHTML){
p.outerHTML =' < pre>'+ text +'< / pre>';
p = e.lastChild;
}
else p.innerHTML = text;
Behaviour.applySubtree(p);
if(stickToBottom)scroller.scrollToBottom();
}

e.fetchedBytes = rsp.getResponseHeader(X-Text-Size);
e.consoleAnnotator = rsp.getResponseHeader(X-ConsoleAnnotator);
if(rsp.getResponseHeader(X-More-Data)==true)
setTimeout(function(){fetchNext(e,href);}
else
$(spinner)。style.display =none;
}
});

具体来说,我希望有一种方法让我从 text 无论它是什么。我不熟悉这种语言,所以不知道我如何能够得到我想要的内容。


解决方案

你做了很好的调查。我只能添加以下:所有控制台相关的插件我知道是设计为后构建操作。


日志触发器插件提供了一个后构建操作,允许Hudson
构建来搜索其控制台日志中给定的正则表达式,
如果找到,触发其他下游作业。


所以看起来你的问题没有直接的解决方案。我可以看到以下选项:



1。使用 tee 或类似的东西(仅适用于shell生成步骤)



这个解决方案远不是通用的,提供对由命令或命令集生成的最新控制台输出的快速访问。


tee - 从标准输入读取并写入标准输出和文件


在系统级别使用同义词其他Jenkins构建步骤可以修改,以产生控制台输出。具有控制台输出的文件可以通过Jenkins或使用任何其他方式引用。



2。修改Jenkins代码



您可以快速修复内部使用情况,或提供修补程序,以引入特定的系统范围设置。



3。模拟/控制台行为



示例中的代码用于从Jenkins服务器请求更新。正如你可能期望的,服务器端可以返回从一些偏移量开始的信息。



>






参数很简单:








响应是要添加的一大块信息:








/ strong>



p>




通过分析Content-Length可以轻松了解没有数据
$ b






所以答案是:使用 url / job-name / build-number / logText / progressiveHtml ,指定起始偏移,发送请求和接收控制台更新。


I have been scouring the internet for days, I have a problem similar to this.

I need to retrieve the console output in raw (plain) text. But if I can get it in HTML that is fine too, I can always parse it. The only thing is that I need to get it during the build step, which is a problem since the location where it should be available is truncated...

I have tried retrieving the console output from the following URL's (relative to the job):

  • /consoleText
  • /logText/progressiveText
  • /logText/progressiveHTML

The two text ones are plain text and would be perfect if not for the truncation, same goes for the HTML one... exactly what I need - only its truncated....

I am sure it is possible to retrieve this information somehow, since when viewing /consoleFull there is a real-time update of the console, without truncating or buffering.

However, upon examining that web page, instead of finding the content I desired, I found this code where it should have been (I did not include the full pages code, since it would be mostly irrelevant, and I believe those answering would be able to find out and know what should be there on their own)

      new Ajax.Request(href,{
          method: "post",
          parameters: {"start":e.fetchedBytes},
        requestHeaders: headers,
          onComplete: function(rsp,_) {

          var stickToBottom = scroller.isSticking();
          var text = rsp.responseText;
          if(text!="") {
            var p = document.createElement("DIV");
            e.appendChild(p); // Needs to be first for IE
            // Use "outerHTML" for IE; workaround for:
            // http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
            if (p.outerHTML) {
              p.outerHTML = '<pre>'+text+'</pre>';
              p = e.lastChild;
            }
            else p.innerHTML = text;
            Behaviour.applySubtree(p);
            if(stickToBottom) scroller.scrollToBottom();
          }

          e.fetchedBytes     = rsp.getResponseHeader("X-Text-Size");
          e.consoleAnnotator = rsp.getResponseHeader("X-ConsoleAnnotator");
            if(rsp.getResponseHeader("X-More-Data")=="true")
              setTimeout(function(){fetchNext(e,href);},1000);
          else
              $("spinner").style.display = "none";
          }
      });

Specifically, I am hoping there is a way for me to get the content from text whatever it may be. I am not familiar with this language and so am not sure how I might be able to get the content I want. Plugins won't help since I want to retrieve this content as part of my script during the build step

解决方案

You did pretty much good investigation already. I can only add the following: all console related plug-ins I know are designed as a post build actions.

The Log Trigger plugin provides a post-build action that allows Hudson builds to search their console log for a given regular expression and if found, trigger additional downstream jobs.

So it looks like there is no straightforward solution to your problem. I can see the following options:

1. Use tee or something similar (applicable to shell build steps only)

This solution is far from being universal, but it can provide quick access to the latest console output, produced by a command or set of command.

tee - read from standard input and write to standard output and files

Using synonyms on the system level other Jenkins build steps can modified in order to produce console output. File with console output can be referenced through Jenkins or using any other way.

2. Modify Jenkins code

You can just do a quick fix for internal usage or provide a patch introducing specific system-wide setting.

3. Mimic /console behavior

Code in your example is used to request updates from the Jenkins server. As you may expect the server side can return piece of information starting with some offset. Let me show.


Periodically console page sends requests to the server:


Parameters are straightforward:


Response is a chunk of information to be added:


Another request with updated offset (start) value


You can easily understand there is no data by analyzing Content-Length


So the answer is: use url/job-name/build-number/logText/progressiveHtml, specify start offset, send request and receive console update.

这篇关于Jenkins - 在构建步骤期间检索完整的控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆