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

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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?

            Assignee:
            magnayn
            Reporter:
            Marco Franssen
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: