<p>I think what you are doing wrong is the way you specify the credentialID to be used. </p>

<p>Instead of <code>'awsId'</code> try to use <code>'ecr:ap-southeast-1:awsId'</code></p>

<pre><code>docker.withRegistry('https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/', 'ecr:ap-southeast-1:awsId') {
    def image = docker.image("01234.dkr.ecr.ap-southeast-1.amazonaws.com/tas/master-server:${env.BUILD_ID}")
    image.push()                                        
}

</code></pre>

<p>EDIT: Check the <a href="https://plugins.jenkins.io/amazon-ecr/" rel="nofollow noreferrer">plugin doc</a></p>

CC BY-SA 4.0
2020-04-23T13:40:43.323Z
2020-04-23T13:40:43.323Z
nandilov
<p>Use this instead:</p>

<pre class="lang-java prettyprint-override"><code>script {
    sh "`aws ecr get-login --region ap-southeast-1 --no-include-email`"
    docker.image('01234.dkr.ecr.ap-southeast-1.amazonaws.com/&lt;yourImage&gt;:&lt;yourTag&gt;')
}
</code></pre>

CC BY-SA 4.0
2020-04-23T11:30:16.303Z
Could you please explain _why_ one should use this instead? Thanks!
Bruce Becker
CC BY-SA 4.0
2020-04-23T15:27:56.887Z
easy to use, based on known aws cli ecr api syntax
dimisjim
CC BY-SA 4.0
2020-04-23T09:57:51.483Z
2020-04-23T09:57:51.483Z
dimisjim
<p>I have a Jenkinsfile that I need to login to ECR. this is the relevant section</p>

<pre><code>        script {
          docker.withRegistry('https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/', 'awsId'){
            def image = docker.image("01234.dkr.ecr.ap-southeast-1.amazonaws.com/tas/master-server:${env.BUILD_ID}")
            image.push()
          }
</code></pre>

<p>But what gets output in the jenkins build is the strange part</p>

<pre><code>$ docker login -u AKIAZWB**********HET -p ******** https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: login attempt to https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/v2/ failed with status: 401 Unauthorized
</code></pre>

<p>I remember if one runs <code>aws ecr get-login</code> the <code>-u</code> is AWS, not the access key of the credentials. So where do I get this wrong?</p>

<jenkins-pipeline><docker-registry><aws-ecr>
unable to login using docker registry on jenkins
Moses Liao GZ
# unable to login using docker registry on jenkins

(Asked by: username_0 on 2020-04-23)

I have a Jenkinsfile that I need to login to ECR. this is the relevant section
        script {
          docker.withRegistry('https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/', 'awsId'){
            def image = docker.image("01234.dkr.ecr.ap-southeast-1.amazonaws.com/tas/master-server:${env.BUILD_ID}")
            image.push()
          }

But what gets output in the jenkins build is the strange part
$ docker login -u AKIAZWB**********HET -p ******** https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: login attempt to https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/v2/ failed with status: 401 Unauthorized

I remember if one runs aws ecr get-login the -u is AWS, not the access key of the credentials. So where do I get this wrong?

**Tags:** jenkins-pipeline, docker-registry, aws-ecr


---

## 2 answers

### Answer by username_1 on 2020-04-23. Score: 1

I think what you are doing wrong is the way you specify the credentialID to be used. 
Instead of 'awsId' try to use 'ecr:ap-southeast-1:awsId'
docker.withRegistry('https://01234.dkr.ecr.ap-southeast-1.amazonaws.com/', 'ecr:ap-southeast-1:awsId') {
    def image = docker.image("01234.dkr.ecr.ap-southeast-1.amazonaws.com/tas/master-server:${env.BUILD_ID}")
    image.push()                                        
}


EDIT: Check the plugin doc


---

### Answer by username_2 on 2020-04-23. Score: 0

Use this instead:
script {
    sh "`aws ecr get-login --region ap-southeast-1 --no-include-email`"
    docker.image('01234.dkr.ecr.ap-southeast-1.amazonaws.com/:')
}

> **Comments:**
> **username_3**: Could you please explain _why_ one should use this instead? Thanks!  
> **username_2**: easy to use, based on known aws cli ecr api syntax  

---

