Is Jenkins logger buffered? If so is there any way to "flush" it?

773 views
Skip to first unread message

Daniel Anechitoaie

unread,
Apr 13, 2019, 3:27:04 PM4/13/19
to Jenkins Developers
I'm writing a pipeline Step plugin and in case build fails for any reason I need to publish the build log somewhere.
So I'm thinking of using "Run.getLog(nr)".

Any idea if I'll have problems with the log buffering/net being flushed when the build fails?

The way the plugin is going to be used is something like this:

node {
    try {
        stage('Something 1') {
        
        }

        stage('Something 2') {
        
        }

        stage('Something 3') {
        
        }
    } catch (e) {
        myPlugin()
        throw e
    }
}


So if any of the stages fail, when I call myPlugin() in "catch" if inside my plugin I call  "Run.getLog(nr)" will I get the full log (of what happened up to that point)? Or it's possible I'll get partial log in some cases due caching/buffering?

Ullrich Hafner

unread,
Apr 14, 2019, 11:32:55 AM4/14/19
to Jenkins Developers
You might not get everything, see https://issues.jenkins-ci.org/browse/JENKINS-32191.

I’m calling sleep in the warnings recorder step for 5 seconds to avoid the problem, this hack works quite well.

You can obtain the log for the individual stages by following Jesse’s instructions in 


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/5c9aeda8-4d0a-4d02-8035-43eef22be8ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Glick

unread,
Apr 15, 2019, 9:07:07 AM4/15/19
to Jenkins Dev
On Sat, Apr 13, 2019 at 3:27 PM Daniel Anechitoaie
<danie...@gmail.com> wrote:
> } catch (e) {
> myPlugin()
> throw e
> }

Not really sure what you are trying to accomplish here, but this does
not smell like a good idea.

Daniel Anechitoaie

unread,
Apr 15, 2019, 10:40:11 AM4/15/19
to Jenkins Developers
What I'm trying to do is integrate with GitHib Checks API so I need to be able to post three types of events to GitHub.
1) When build started (which I did as a pipeline step plugin - gitHubCheckRunBegin())
2) When build was successful (which I did as a pipeline step plugin - gitHubCheckRunEnd())
3) When build fails. Here I would need to get the output of the stage the failed to be able to send that to GitHub.

For #3 I did as you suggested from @Ullrich link as a block scoped function which seems perfect.

Dos it make sense? Is it ok the way it was done?

And I'm planing to use this like:

node {
    def cfg = [
        'stuff': 'stuff',
        ...
    ]

    stage('Cleanup') {
        cleanWs()
    }

    stage('Git') {
        git(...)
    }

    stage('CheckRun_Begin') {
        gitHubCheckRunBegin(cfg)
    }

    stage('Yarn') {
        withGitHubCheckRun(cfg) {
            sh(...)
        }
    }

    stage('Build') {
        withGitHubCheckRun(cfg) {
            sh(...)
        }
    }

    stage('CheckRun_End') {
        gitHubCheckRunEnd(cfg)
    }
}

So at start gitHubCheckRunBegin makes call to GitHub api to start the check, gitHubCheckRunEnd will make call to GitHub api to end the check successfully (assuming the job gets there).
And if any step fails then the withGitHubCheckRun will catch that stage output and push it the GitHub API

Jesse Glick

unread,
Apr 15, 2019, 1:51:59 PM4/15/19
to Jenkins Dev
On Mon, Apr 15, 2019 at 10:41 AM Daniel Anechitoaie
<danie...@gmail.com> wrote:
> 3) When build fails. Here I would need to get the output of the stage the failed to be able to send that to GitHub.

I guess you could capture the stage output, but this could in general
be massive. Do you really need to send it to GitHub? JENKINS-28119
might be a better approach: just send GitHub a link back to Jenkins.

> For #3 I did as you suggested from @Ullrich link as a block scoped function which seems perfect.

You could call `StepContext.saveState` to ensure that all output is
recorded even if Jenkins is restarted in the middle of the stage.
Other than that, I think it would work, other than the scalability
problem.

Daniel Anechitoaie

unread,
Apr 15, 2019, 1:57:40 PM4/15/19
to Jenkins Developers
The output that the stages will do is controlled so there will be at most 30-40 lines of text.
And also I'll truncate the text before sending it to GH if it's beyond a certain size.
Reply all
Reply to author
Forward
0 new messages