Jenkinsfile build log

后端 未结 3 1105
梦如初夏
梦如初夏 2021-01-04 01:22

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

I tried using something like currentBuild.log, curre

3条回答
  •  伪装坚强ぢ
    2021-01-04 02:08

    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.

提交回复
热议问题