title: Auth into ECR in a Jenkinsfile so I can pull an image to run the build in?
body: <p>The situation here is that we have an app that's currently being built on a Jenkins slave with a certain version of node installed on it. We want to standardize the build environment, and so to do that want to build inside a docker container.</p>
  
  <p>Through my research it <a href="https://jenkins.io/doc/book/pipeline/docker/#custom-registry" rel="noreferrer">definitely seems possible</a>. However, the challenge for us is we want to use custom images we manage ourselves and store in ECR. We don't want to use the ones on docker hub. With that constraint in mind, I'm struggling to authenticate into our ECR within my Jenkinsfile. Ideally I could do something like this:</p>
  
  <pre><code>pipeline {
      agent {
          docker {
              image 'node:7'
              registryUrl 'ecr_url.amazonaws.com'
              registryCredentialsId 'ecr:us-east-1:iam_role'
          }
      }
      stages {
          stage('Build') {
              steps {
                  sh 'command goes here'
              }
          }
      }
  }
  </code></pre>
  
  <p>But the issue here is that our ECR login relies on running a shell command on the Jenkins worker  (which has aws cli installed) to log in and access the image. So far I've had no luck authenticating within the Jenkinsfile so I can pull an image to run the build in. Does anyone know if this is possible and if so, how to edit the Jenkinsfile to do it?</p>