jenkinsci / hetzner-cloud-plugin

Hetzner cloud integration for Jenkins
https://plugins.jenkins.io/hetzner-cloud/
Apache License 2.0
24 stars 8 forks source link

NullPointerException if job without label triggers provisioning #15

Closed mfussenegger closed 2 years ago

mfussenegger commented 2 years ago

Jenkins and plugins versions report

Environment ```text Paste the output here ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu 20.04.3 LTS x86_64 for both the jenkins master and for the cloud images.

Reproduction steps

  1. Configure a cloud runner with mode=NORMAL and some lables
  2. Ensure there are no other jenkins runner nodes
  3. Create a job without any label

I used the configuration-as-code plugin to define a seed job:

job('job-dsl') {
  description "Seed job"
  parameters {
    stringParam('BRANCH', 'master')
  }
  scm {
    git {
      remote {
          github('some-org/some-repo', 'ssh')
      }
      branch '${BRANCH}'
    }
  }
  triggers {
    githubPush()
  }
  steps {
    jobDsl {
      failOnMissingPlugin true
      ignoreExisting false
      ignoreMissingFiles false
      lookupStrategy 'JENKINS_ROOT'
      removedConfigFilesAction 'DELETE'
      removedJobAction 'DELETE'
      removedViewAction 'DELETE'
      targets 'jobs/**/*.groovy'
    }
  }
}
  1. Trigger that job

If a label('something') is added to the job, everything works as expected.

Let me know if you need more information to reproduce it. The installation where I encountered this is otherwise pretty fresh

Expected Results

Jenkins runner spawns and job gets scheduled on it

Actual Results

No runner spawns and exceptions appear in the log:

java.lang.NullPointerException
    at cloud.dnation.jenkins.plugins.hetzner.HetznerCloud.lambda$getTemplates$1(HetznerCloud.java:172)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
    at cloud.dnation.jenkins.plugins.hetzner.HetznerCloud.getTemplates(HetznerCloud.java:175)
    at cloud.dnation.jenkins.plugins.hetzner.HetznerCloud.canProvision(HetznerCloud.java:163)
    at hudson.slaves.NodeProvisioner$StandardStrategyImpl.apply(NodeProvisioner.java:702)
    at hudson.slaves.NodeProvisioner.update(NodeProvisioner.java:325)
    at hudson.slaves.NodeProvisioner.access$1000(NodeProvisioner.java:70)
    at hudson.slaves.NodeProvisioner$NodeProvisionerInvoker.doRun(NodeProvisioner.java:815)
    at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:90)
    at jenkins.security.ImpersonatingScheduledExecutorService$1.run(ImpersonatingScheduledExecutorService.java:67)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

Anything else?

Now that I know that the problem was that the job has no label it's not really an issue - but might save others some trouble if this gets fixed.

rkosegi commented 2 years ago

Thank you for bug report. Looks like this regression was introduced by changes for #12. I will look into it.

rkosegi commented 2 years ago

This should be fixed now