Jenkinsfile build log

二次信任 提交于 2019-12-04 00:05:59

问题


Is there any builtin variable that gives access to the text of the currently executing build?

I tried using something like currentBuild.log, currentBuild.buildLog but without any luck.


回答1:


Actually it is possible using currentBuild.rawBuild.log or better (not deprecated) currentBuild.rawBuild.getLog(100) (for the last 100 lines), reference: http://javadoc.jenkins-ci.org/hudson/model/Run.html#getLog-int-




回答2:


I searched a lot for a solution to analyze the log.

  • use rawBuild was not OK, because I want to execute my scripts in a sandbox without additional approvals
  • use tee in the steps, that I want to analyse was not OK, because I don't want to modify previous steps, nor I don't want to have my whole log in RAM (and unfortunately I needed that on a Windows machine)

I found a solution inspired by Jesse Glicks answer:

  • Under my.jenkins.url/pipeline-syntax/globals you can see, that the manager-variable allows you to analyse the log by using manager.logContains(regexp) or manager.getLogMatcher(regexp)
  • So if you just want to check, that your log contains string myTestString you can just call manager.logContains('.*myTestString.*')
  • If you want to get some information from the first matching line you can use manager.getLogMatcher(regexp)

Unfortunately I found no way to analyze the whole log (getLogMatcher returns only the first matching line Matcher). So I see currently no way to e.g. count how often a log file contains a special string.




回答3:


Not currently. (Properties of currentBuild are documented under Snippet Generator » Global Variables by the way.)

It could be implemented, fairly easily, though it would not scale well with huge builds. JENKINS-28119 would provide a more scalable solution to what I am guessing your underlying request is.



来源:https://stackoverflow.com/questions/37018509/jenkinsfile-build-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!