Maven Projects trigger RunListener twice

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Maven Projects trigger RunListener twice

Kyle Flavin-2
Hi,
I'm working on a Jenkins plugin to gather metrics from completed jobs.  This primarily involves gathering label information from Executors.  I'm using  RunListener that looks something like this:

@Extension
public class MyRunListener extends RunListener<Run> implements Describable<MyRunListener> {
 
@Override
 
public void onCompleted(Run run, @Nonnull TaskListener listener) {
     
// collect executor labels, send them off to an API endpoint
 
}
}

This is working fine for most of my projects.  Pipeline, Multibranch, and Freestyle jobs each trigger onCompleted() when the build finishes.  I've noticed some odd behavior from Maven projects though; they trigger onCompleted twice for each build, instead of just once.

Here are some things I've noticed:
  • The first time my code is triggered, run.getParent().getClass() is of type hudson.maven.MavenModule, and the executor is null (run.getExecutor() == null), so I can't pull any information from the Executor.  The url in the build data also adds the artifact id into the url like so:  http://localhost/jenkins/job/maven-job/com.company.jenkins.plugins$artifactidname/5/ which makes for a non-working link.
  • The second time it is triggered, run.getParent().getClass is of type hudson.maven.MavenModuleSet, and run.getExecutor() returns an Executor with node information.  The url in the build data points to the correct build location: http://localhost/jenkins/job/maven-job/5/.  This appears to be the information I want.
I'm wondering what the difference is between MavenModule and MavenModuleSet.  Can I safely ignore anything of type MavenModule for my purposes, without losing any job data?  In other words, are there any scenarios where a Maven project would NOT behave like this, and only trigger my Listener once, as a MavenModule or MavenModuleSet, but not both?

Thanks!
Kyle

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/0f1bf9d8-4ca0-40bc-943b-defdc9d1efd5%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Maven Projects trigger RunListener twice

Jesse Glick-4
`maven-plugin` does weird things with nested jobs/builds. We advise
people to not use this plugin.

You may want to test against `matrix-project`, which also does
something similar, though in that case each sub-build would in fact
have different executor labels.

I am not sure what you tested for Pipeline but if you are trying to
collect executor labels, `RunListener` is not going to do what you
want, since a given Pipeline build might have run zero or more `node`
blocks. If you do not need this information in real time, I guess you
can wait for the whole build to complete, then traverse the flow graph
looking for `WorkspaceAction`.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr3DSDy%3D8VcChOL4xQzZYCrD9aTOYkG0%2B2SaZ_ft%3DbwkdA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Maven Projects trigger RunListener twice

Kyle Flavin-2
Got it.  We're encouraging people to move towards pipeline, but we still have a lot of these Maven jobs in our environment (across multiple masters).  I'll share this internally.

Collecting labels on the pipeline jobs has been a bit of a challenge, but what I've settled on is what you describe.  I wait until the build is complete, and then I traverse the flow graph.  We don't really need the data in real time, so it seems to work well enough.  If you can suggest a different approach though, I'm open to improving it.

Thanks!

On Wednesday, September 4, 2019 at 8:54:37 AM UTC-7, Jesse Glick wrote:
`maven-plugin` does weird things with nested jobs/builds. We advise
people to not use this plugin.

You may want to test against `matrix-project`, which also does
something similar, though in that case each sub-build would in fact
have different executor labels.

I am not sure what you tested for Pipeline but if you are trying to
collect executor labels, `RunListener` is not going to do what you
want, since a given Pipeline build might have run zero or more `node`
blocks. If you do not need this information in real time, I guess you
can wait for the whole build to complete, then traverse the flow graph
looking for `WorkspaceAction`.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/5951caf4-210f-4a05-93f1-ca3bd9c656c9%40googlegroups.com.