Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-43324

use docker.withRegistry from pipeline stage steps doesn't work

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I'm trying to use following pipeline script to build a docker image from my code. I just can't figure out how to define my pipeline without errors.

       

      node {
          registry_url = 'https://my.registry.com/'
      }
      pipeline {
          agent any
          tools {
              nodejs 'Node6'
          }
      
          stages {
              stage('Build') {
                  steps {
                       withNPM(npmrcConfig: '1aa61c52-21e9-488c-a989-4ca4bc7baac3') {
                          sh '''
                              npm install --silent
                              npm run dist
                          '''
                      }
                  }
              }
              stage('Dockerize') {
                  steps {
                      // This fails with the error shown in next code block
                      docker.withRegistry("${registry_url}"'my-login-credential') {
                          def customerUi = docker.build "omnius-vnext-customer-ui:${env.BUILD_TAG}"
                          customerUi.push
                      }
                  }
              }
      }

      The error happening at the docker.withRegistry

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      WorkflowScript: 30: Method calls on objects not allowed outside "script" blocks. @ line 30, column 17.
                         docker.withRegistry("${registry_url}", 'Nexus') {
                         ^
      
      WorkflowScript: 30: "error" should have 1 arguments but has 3 arguments instead. @ line 30, column 17.
                         docker.withRegistry("${registry_url}", 'Nexus') {
                         ^
      
      2 errors
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
      	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
      	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67)
      	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:430)
      	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:393)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:238)
      	at hudson.model.ResourceController.execute(ResourceController.java:98)
      	at hudson.model.Executor.run(Executor.java:405)
      

      How can I use the docker plugin within my pipeline steps?

        Attachments

          Activity

          Hide
          alonbl Alon Bar-Lev added a comment -

          yes, just found this as well. I thought something wrong with me... why is there a difference between node context and stage context?

          Show
          alonbl Alon Bar-Lev added a comment - yes, just found this as well. I thought something wrong with me... why is there a difference between node context and stage context?
          Hide
          030 030 030 added a comment -

          I am experiencing the same issue: https://devops.stackexchange.com/q/2143/210

          Show
          030 030 030 added a comment - I am experiencing the same issue: https://devops.stackexchange.com/q/2143/210
          Hide
          jglick Jesse Glick added a comment -

          User error. I responded on Stack Exchange.

          Show
          jglick Jesse Glick added a comment - User error. I responded on Stack Exchange.

            People

            Assignee:
            magnayn magnayn
            Reporter:
            marcofranssen Marco Franssen
            Votes:
            5 Vote for this issue
            Watchers:
            9 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: