title: Use private docker registry with Authentication in Jenkinsfile
body: <p><strong>How can I teach my Jenkisfile to login via basic auth in this setup?</strong></p>
  
  <p>I'm using a custom docker image for my Jenkins build. 
  As described in the documentation <a href="https://jenkins.io/doc/book/pipeline/syntax/" rel="noreferrer">here</a> I defined a docker agent like so:</p>
  
  <pre><code>pipeline {
  agent { 
      docker {
          image 'registry.az1:5043/maven-proto'
          registryUrl 'https://registry.az1'
          args '-v /var/jenkins_home/.m2:/root/.m2'
      }
  }
  options {
      timeout(time: 1, unit: 'HOURS')
      buildDiscarder(logRotator(numToKeepStr:'10'))
  }
  
  stages {
      stage ('Build') {
          steps{
              sh ...
          }
      }
  
      stage ('Test') {
          steps {
              sh ...
          }
      } 
  
       stage ('Deploy') {
          steps {
              sh ...
          }
      }
  }
  
  post {
      always {
          echo 'Clean up workspace'
          deleteDir()
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If I use the following agent setup: </p>
  
  <pre><code>pipeline {
  agent { 
      docker.withRegistry('https://registry.az1', 'registry_login'){
          image 'registry.az1:5043/maven-proto'
          registryUrl 'https://registry.az1'
          args '-v /var/jenkins_home/.m2:/root/.m2'
      }
  }
  </code></pre>
  
  <p>The execution of the pipeline fails with the following exception:</p>
  
  <pre><code>WorkflowScript: 3: Too many arguments for map key "withRegistry" @ line 3, column 16.
         docker.withRegistry('https://registry.az1', 'registry_login'){
                ^
  
  WorkflowScript: 3: Invalid agent type "withRegistry" specified. Must be one of [docker, dockerfile, label, any, none] @ line 3, column 16.
             docker.withRegistry('https://registry.az1', 'registry_login'){
                    ^
  </code></pre>
  
  <p>The problem is that the used registry requires a basic auth login. The registry runs behind a nginx reverse proxy using <a href="https://docs.docker.com/registry/recipes/nginx/" rel="noreferrer">this</a> configuration. </p>