Skip to content

NPE in abortRunningJobsThatMatch #13

@jlongman

Description

@jlongman

Hi, love the plugin, it's awesome. Thank you.

I am running BBPRB v.0.3.0 on Jenkins v.2.121.2.

I recently converted a job from a normal build to a pipeline workflow - it allows easier access to doing programmatic search for ambiguously defined dependencies (sigh). Ie I can search other builds to find products of a similarly named branch in a separate repo.

Unfortunately now when I do this I now get stack traces in my jenkins backend when the job should be triggered:

WARNING: Error while serving https://jenkins.protmv.com/bbprb-hook/
java.lang.reflect.InvocationTargetException
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:347)
[...]
Caused by: java.lang.NullPointerException
	at org.jenkinsci.plugins.bbprb.BitbucketBuildTrigger.abortRunningJobsThatMatch(BitbucketBuildTrigger.java:214)
	at org.jenkinsci.plugins.bbprb.BitbucketBuildTrigger.startJob(BitbucketBuildTrigger.java:156)
	at org.jenkinsci.plugins.bbprb.BitbucketBuildTrigger.handlePR(BitbucketBuildTrigger.java:282)
	at org.jenkinsci.plugins.bbprb.BitbucketHookReceiver.doIndex(BitbucketHookReceiver.java:108)
	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
[...]

Looking at the code there (Note, I've added the WARNING logging):

  private void
  abortRunningJobsThatMatch(@Nonnull BitbucketCause bitbucketCause) {
    logger.log(Level.FINE, "Looking for running jobs that match PR #{0}",
               bitbucketCause.getPullRequestId());
\\    logger.log(Level.WARNING, "job: " + (job != null? job.toString() : "null - no job"));
\\    logger.log(Level.WARNING, "job-builds: " + (job.getBuilds() != null? job.getBuilds().toString() : "null - no jobbuilds"));
    for (Object o : job.getBuilds()) {
      if (o instanceof Run) {
        Run build = (Run)o;
        if (build.isBuilding() &&
            hasCauseFromTheSamePullRequest(build.getCauses(), bitbucketCause)) {

the logging shows the this.job is null.

It looks like WorkflowJob does not have AbstractProject as an ancestor, and maybe this explains this behaviour in some weird way. A quick search shows this seems to be on "purpose".

I looked at quickly adding something that would work but realized that my first thought of checking types in startJob for ParameterizedJob would fail as scheduleBuild2 there lacks the necessary signature.

I don't understand why this.jobs is null in that later method so I'm pretty sure I don't understand what's going on.

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions