Hi Jesse,

I'm hoping you can point me in the right direction for one more thing.  I'm 
trying to understand at what point in the pipeline process does the build 
result (via run.getResult()) become available?  As you can see below, I'm 
calling the original FlowdockNotifier code in a step execution in order to 
be able to use the "legacy" plugin in a pipeline.  I'm including two blocks 
below.  First is how it's being used in a pipeline, and the second is the 
step execution code.

The issue is that run.getResult() is returning null even when used in a 
pipeline *after* which the build should have failed (e.g. after failing to 
pass unit tests or compilation).  I'm wondering if there is something I 
need to do to ensure that I get the proper build result from the job and 
have this step run only after that.

Here's the pipeline.  In this example, I was assuming that by running the 
flowdockNotifier in the pipeline, I'd already have the correct build result 
in place as a result of the mvn build in the previous section.  Instead, 
I'm getting null for run.getResult() no matter what.  Is there something 
different I should be doing to ensure that the flowdockNotifier is only run 
after we've received some sort of build result?  The Flowdock plugin 
traditionally has been a Notifier and run as a post build action.

        try {
            sshagent([config.gitCredentials]) {

                withMaven(maven: 'Maven', mavenLocalRepo: '.repository', 
mavenSettingsConfig: 
'org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig1450194231885') 
{
                    sh "mvn versions:set -DnewVersion=${version}"
                    sh "mvn clean install"
                }                
                          }

             } catch (err) {
            mail body: "Please go to ${BUILD_URL} and verify the build." ,
                from: config.email,
                replyTo: config.email,
                subject: "Build failed in Jenkins: ${JOB_NAME} ${version}",
                to: config.recipients

            throw err
        } finally {
            // Post build items here -- build will have already passed or 
failed by now?
            flowdockNotifier(flowToken: 'myflowdocktoken', 
notificationTags: "jenkins, ${JOB_NAME}",
                chatNotification:true, notifyFailure: true)

        }

Here's the step execution.

    *public* *static* *class* Execution *extends* 
AbstractSynchronousStepExecution<Void> {

       

       @StepContextParameter *private* *transient* Launcher launcher;

       @StepContextParameter *private* *transient* FilePath workspace;

       @StepContextParameter *private* *transient* TaskListener listener;

       @StepContextParameter *private* *transient* Run<?, ?> run;

       @StepContextParameter *private* *transient* EnvVars env;

       @Inject(optional=*true*) *private* *transient* FlowdockNotifierStep 
step;


        @Override

       *protected* Void run() *throws* Exception {

           listener.getLogger().println("Running flowdock notifier.");

           

           FlowdockNotifier notifier = *new* FlowdockNotifier(step.flowToken
,

                        step.notificationTags, 

                        convertToString(step.chatNotification),

                        convertToString(step.notifySuccess),

                        convertToString(step.notifyFailure),

                        convertToString(step.notifyFixed),

                        convertToString(step.notifyUnstable), 

                        convertToString(step.notifyAborted),

                        convertToString(step.notifyNotBuilt));

           

           notifier.perform(run, workspace, launcher, listener);


            *return* *null*;        

       }


        *private* *static* *final* *long* *serialVersionUID* = 1L;


        *private* *static* String convertToString(Boolean bool) {

          *return* bool != *null* ? bool.toString() : *null*;

       }

   }

Thanks for any help,
Tim

On Tuesday, November 1, 2016 at 5:55:55 PM UTC-4, Jesse Glick wrote:
>
> On Tue, Nov 1, 2016 at 2:04 PM, Tim Downey <timothy...@gmail.com 
> <javascript:>> wrote: 
> >        if(build.getProject().getRootProject() != build.getProject()) { 
> >            projectName = 
> > build.getProject().getRootProject().getDisplayName(); 
> >            configuration = " on " + build.getProject().getDisplayName(); 
> >        } else { 
> >            projectName = build.getProject().getDisplayName(); 
> >        } 
> > 
> > 
> > From the call, I've switched the fromBuild method to take Run<?,?> 
> instead 
> > of AbstractProject 
>
> Instead of `AbstractBuild` I suppose you mean. 
>
> > but the issue is that I'm not clear on what needs to be 
> > done in the conditional.  The existing code seems to be trying to figure 
> out 
> > if it is the root project in order to construct the message (which will 
> be 
> > sent to flowdock) but I'm not sure what the equivalent would be when 
> working 
> > from Run instead of AbstractProject. 
>
> There is no generalization of `AbstractProject.getRootProject` 
> currently. You can check if the `Job` is in fact an `AbstractProject` 
> and if so call `getRootProject` on it, else just use the job as is. 
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/e8977e41-e9c5-4616-b2d0-f17b463684b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to