Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkinsfile build log

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.

like image 224
Krzysztof Krasoń Avatar asked May 04 '16 04:05

Krzysztof Krasoń


People also ask

How do I know if Jenkins build failed?

In Jenkins, in the pipeline where failure occurred, in the pane, select the latest build, and click Console Output. On the Console Output page, check the logs to find the reason for the failure. If required, update the parameters in the deployment input configuration file.

How do I view Jenkins logs in Windows?

Now open a new tab in your web browser and type the URL http://192.168.33.10/logs/jenkins. You will see all the content of the Jenkins server /var/log/jenkins folder, including the jenkins. log file!

What is currentBuild in Jenkins?

currentBuild is a global variable that may be used to refer to the currently running build.


2 Answers

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-

like image 61
Krzysztof Krasoń Avatar answered Oct 15 '22 22:10

Krzysztof Krasoń


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.

like image 38
Sergej Werfel Avatar answered Oct 15 '22 23:10

Sergej Werfel