Pipeline Build Wrapper

47 views
Skip to first unread message

Steven F

unread,
Jun 26, 2017, 11:39:53 AM6/26/17
to Jenkins Developers
Hi,

I'm trying to write a plugin that imposes a limit on a build. A previous plugin achieved this using a build wrapper which started a repeating scheduled task. In a pipeline it seems like a build wrapper has to be applied as a block in the script instead of being able to apply to the entire build. This makes it opt-in whereas I'd like to define this limit outside of the script as an administrator.

Is a build wrapper the wrong approach for this behavior? I'd like a parameter on the build config page and a scheduled task which begins when the build starts. Is this style of plugin incompatible with pipelines, or is there a particular approach I should take?

Jesse Glick

unread,
Jun 26, 2017, 3:29:02 PM6/26/17
to Jenkins Dev
On Mon, Jun 26, 2017 at 11:18 AM, Steven F <steven...@gmail.com> wrote:
> I'd like a
> parameter on the build config page

Possible, via the `FlowDefinition` extension point, but probably not
what you actually want, since this will not work with multibranch
Pipelines.

I suppose the most generic solution would be a `RunListener` that
aborts a build after some time. This has some clear problems in
relation to Pipeline, such as (arguably improperly) aborting a build
which is just sitting in `input` and harming no one. Depends on what
you are trying to accomplish.

Steven F

unread,
Jun 26, 2017, 5:25:48 PM6/26/17
to Jenkins Developers
Hmm, interesting. I briefly tried with the RunListener approach but the interruption of the build didn't seem quite right. It wasn't taking on the Result that I passed, but it did interrupt, so I thought it might cause unseen issues. Also, I wasn't sure how to clean up the scheduled task that I was starting.

I'll have another look at RunListener though. It's just to fail a build once the build log file size is over a certain threshold.

Jesse Glick

unread,
Jun 26, 2017, 5:35:10 PM6/26/17
to Jenkins Dev
On Mon, Jun 26, 2017 at 5:25 PM, Steven F <steven...@gmail.com> wrote:
> It's just to fail a build once
> the build log file size is over a certain threshold.

For performance reasons? Cf. JENKINS-38381.

Steven F

unread,
Jun 26, 2017, 5:50:47 PM6/26/17
to Jenkins Developers
Partially, yes. That improvement would help but sometimes a flaw in the build can result in massive log file, even filling the drive. A way to impose a limit as a rule is what I'm after. I'm also taking this as a learning opportunity to explore the different components of Jenkins :)

Jesse Glick

unread,
Jun 26, 2017, 6:17:28 PM6/26/17
to Jenkins Dev
On Mon, Jun 26, 2017 at 5:50 PM, Steven F <steven...@gmail.com> wrote:
> That improvement would help but sometimes a flaw in the
> build can result in massive log file, even filling the drive.

So the simplest thing that could work is to just have a `RunListener`
which starts checking the length of the `logText` and after some
threshold will `Executor.interrupt` it.

Steven F

unread,
Jun 27, 2017, 6:36:30 AM6/27/17
to Jenkins Developers

This worked a lot better now that I understand more what's going on, thanks for the help.

There is a minor issue though where the result passed to Executor.interrupt is being overridden by whatever happens in the pipeline to interrupt it.
e.g., if it's in the middle of a shell script the build will always be marked Failure because of the error caused by interrupting the shell script.
In my case I don't mind because I wanted to mark it failed anyway, but I don't know if other results will come up in other cases.

Jesse Glick

unread,
Jun 28, 2017, 10:39:20 AM6/28/17
to Jenkins Dev
On Tue, Jun 27, 2017 at 6:36 AM, Steven F <steven...@gmail.com> wrote:
> if it's in the middle of a shell script the build will always be
> marked Failure because of the error caused by interrupting the shell script.

cf. JENKINS-28822

Steven F

unread,
Jun 30, 2017, 5:00:36 AM6/30/17
to Jenkins Developers


On Wednesday, June 28, 2017 at 3:39:20 PM UTC+1, Jesse Glick wrote:
cf. JENKINS-28822

 Sorry for another basic question, but do you have the name of a class I should look into to add a global configuration (from Manage Jenkins) that would be accessible to my RunListener? I've used Descriptors with other extension points but it doesn't seem to apply here since there is only one instance. I've also looked into OptionalJobProperty but that wouldn't be on a global level.

Robert Sandell

unread,
Jun 30, 2017, 5:10:37 AM6/30/17
to jenkin...@googlegroups.com

--
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-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/cb4724c6-1138-4739-94e5-cd245573fd60%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Robert Sandell

unread,
Jun 30, 2017, 5:10:45 AM6/30/17
to jenkin...@googlegroups.com
2017-06-30 11:00 GMT+02:00 Steven F <steven...@gmail.com>:

--
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-dev+unsubscribe@googlegroups.com.

Łukasz Zachulski

unread,
Jul 1, 2017, 3:17:41 AM7/1/17
to Jenkins Developers
Hello,

@Steven I'm looking for something which would impose limit to log files as well.

Would you mind sharing your work so I could test your Plugin?

Reply all
Reply to author
Forward
0 new messages