• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • docker-plugin
    • docker plugin 0.16.2
      jenkins 2.7
      insecure docker registry and docker hosts

      If you have credentials == None and a "Build / Publish Docker Containers" build step then, when the build step executes, you get a NullPointerException:

      Docker Build
      ERROR: Build step failed with exception
      java.lang.NullPointerException
      	at com.nirima.jenkins.plugins.docker.utils.JenkinsUtils.makeAuthConfig(JenkinsUtils.java:173)
      	at com.nirima.jenkins.plugins.docker.utils.JenkinsUtils.getAuthConfigurations(JenkinsUtils.java:150)
      	at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run.buildImage(DockerBuilderPublisher.java:273)
      	at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run.run(DockerBuilderPublisher.java:230)
      	at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher.perform(DockerBuilderPublisher.java:361)
      	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
      	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
      	at hudson.model.Build$BuildExecution.build(Build.java:205)
      	at hudson.model.Build$BuildExecution.doRun(Build.java:162)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
      	at hudson.model.Run.execute(Run.java:1741)
      	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      	at hudson.model.ResourceController.execute(ResourceController.java:98)
      	at hudson.model.Executor.run(Executor.java:410)
      Build step 'Build / Publish Docker Containers' marked build as failure

      My docker host is "insecure", hence my docker cloud definition is set to have credentials==None, as does my registry.
      This means that when JenkinsUtils.makeAuthConfig(Credentials) runs, credentials is not instanceof StandardUsernamePasswordCredentials and hence null is returned to makeAuthConfig(DockerRegistry) which then de-references the null and explodes.

      A potential fix is to edit

      JenkinsUtils.java
          protected static AuthConfig makeAuthConfig(DockerRegistry registry) {
              if( registry == null )
                  return null;
      
              Credentials credentials = lookupSystemCredentials(registry.credentialsId);
      
              return makeAuthConfig(credentials).withRegistryAddress(registry.registry);
          }
      

      to be

      JenkinsUtils.java, modified
          protected static AuthConfig makeAuthConfig(DockerRegistry registry) {
              if( registry == null )
                  return null;
      
              Credentials credentials = lookupSystemCredentials(registry.credentialsId);
              final AuthConfig authConfig = makeAuthConfig(credentials);
              if( authConfig == null )
                  return null;
              return authConfig.withRegistryAddress(registry.registry);
          }
      

          [JENKINS-39100] NPE in Build/Publish Docker Container step

          pjdarton added a comment -

          pjdarton added a comment - See pull request https://github.com/jenkinsci/docker-plugin/pull/452

          Code changed in jenkins
          User: Peter Darton
          Path:
          docker-plugin/src/main/java/com/nirima/jenkins/plugins/docker/utils/JenkinsUtils.java
          http://jenkins-ci.org/commit/docker-plugin/6e10e70cce24426fc6f9eadebf8328b356331095
          Log:
          Fix JENKINS-39100 (#452)

          Prevents NPE during JenkinsUtils.makeAuthConfig when dealing with registries that have no username/password defined.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Peter Darton Path: docker-plugin/src/main/java/com/nirima/jenkins/plugins/docker/utils/JenkinsUtils.java http://jenkins-ci.org/commit/docker-plugin/6e10e70cce24426fc6f9eadebf8328b356331095 Log: Fix JENKINS-39100 (#452) Prevents NPE during JenkinsUtils.makeAuthConfig when dealing with registries that have no username/password defined.

          Robert Baker added a comment -

          I tested your patch and it eliminates the NPE we are experiencing, however, we need the official release of the plugin for our production servers.  When can we expect this patch to be released?

          Robert Baker added a comment - I tested your patch and it eliminates the NPE we are experiencing, however, we need the official release of the plugin for our production servers.  When can we expect this patch to be released?

          pjdarton added a comment -

          According to the pull request this was merged into the main code on 3 Nov 2016, but there hasn't been an official release since then.

          The main code has been unchanged since 12 Nov 2016 so I'd guess that the plugin maintainers ( integer and magnayn ) are reasonably happy with it - all that's needed is an official release...

          ...although they'll probably need to add a Jenkinsfile ( e.g. as done here) before it can be built by the Jenkins CI infrastructure.

           

           

          pjdarton added a comment - According to the pull request this was merged into the main code on 3 Nov 2016, but there hasn't been an official release since then. The main code has been unchanged since 12 Nov 2016 so I'd guess that the plugin maintainers ( integer and magnayn ) are reasonably happy with it - all that's needed is an official release... ...although they'll probably need to add a Jenkinsfile ( e.g. as done here ) before it can be built by the Jenkins CI infrastructure.    

            ndeloof Nicolas De Loof
            pjdarton pjdarton
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: