Access current "build" instance from within Workflow Script?

137 views
Skip to first unread message

Kenneth Baltrinic

unread,
Feb 4, 2015, 2:59:02 PM2/4/15
to jenkins...@googlegroups.com
I feel like I have read how to do this somewhere already but now that I need it I can't find it.  I am trying to duplication the behavior of the mailer within a workflow script.  Namely if the build failed send an e-mail.  If it succeed but the previous build failed, send a different email.  In order to do this, I need to access the build object (something that implements AbstractBuild and Run) for the current, in-flight build, so that I can get the current result and the previous build result.  Can someone advise as to how to do this?  Or is there a functionally built into the mail step that I can leverage somehow to send different messages/subjects based on current and previous build status?  

It seems like this is going to be a common need in workflow so perhaps adding an example somewhere in the docs of how to do this might be in order?

Slide

unread,
Feb 4, 2015, 3:01:17 PM2/4/15
to jenkins...@googlegroups.com
Doesn't workflow support using Mailer directly? I thought there was a way to use Mailer in the workflow.

On Wed Feb 04 2015 at 12:59:05 PM Kenneth Baltrinic <ken...@baltrinic.com> wrote:
I feel like I have read how to do this somewhere already but now that I need it I can't find it.  I am trying to duplication the behavior of the mailer within a workflow script.  Namely if the build failed send an e-mail.  If it succeed but the previous build failed, send a different email.  In order to do this, I need to access the build object (something that implements AbstractBuild and Run) for the current, in-flight build, so that I can get the current result and the previous build result.  Can someone advise as to how to do this?  Or is there a functionally built into the mail step that I can leverage somehow to send different messages/subjects based on current and previous build status?  

It seems like this is going to be a common need in workflow so perhaps adding an example somewhere in the docs of how to do this might be in order?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b0fb68ae-61ff-4103-8af6-efe808af1518%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Les Mikesell

unread,
Feb 4, 2015, 4:10:11 PM2/4/15
to jenkinsci-users
On Wed, Feb 4, 2015 at 2:01 PM, Slide <slide...@gmail.com> wrote:
> Doesn't workflow support using Mailer directly? I thought there was a way to
> use Mailer in the workflow.

Not sure about that, but what do you do if you build some other job(s)
within a workflow instead of inlining them - but you want the workflow
job to know the details at the end?

--
Les Mikesell
lesmi...@gmail.com

Kenneth Baltrinic

unread,
Feb 5, 2015, 8:10:01 AM2/5/15
to jenkins...@googlegroups.com
In reading the docs, some Jira issues and the source code, as I understand it, there are two options for sending mail in workflows, you can invoke the standard mailer via the step $class: 'hudson.tasks.Mailer' notation, or you can use the mail step.  The standard mailer is insufficient for our purposes as it does not give enough control over the messages. The extended mailer would be sufficient but is not available via step.  The mail step itself gives enough control but lacks the logic of the mailer plug-in, which is why I am trying to figure out how to the logic myself.  

Kenneth Baltrinic

unread,
Feb 5, 2015, 8:20:31 AM2/5/15
to jenkins...@googlegroups.com
I am just reposting with a new subject since I did not notice the [workflow plugin] convention previously.  Hoping this will get the right peoples eyes on the problem.

Jesse Glick

unread,
Feb 25, 2015, 6:06:20 PM2/25/15
to jenkins...@googlegroups.com
On Wednesday, February 4, 2015 at 2:59:02 PM UTC-5, Kenneth Baltrinic wrote:
I need to access the build object (something that implements AbstractBuild and Run) for the current, in-flight build, so that I can get the current result and the previous build result.

Reply all
Reply to author
Forward
0 new messages