0

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?

2 Answers 2

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

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/<yourImage>:<yourTag>')
}
2
  • 1
    Could you please explain why one should use this instead? Thanks! Commented Apr 23, 2020 at 11:30
  • easy to use, based on known aws cli ecr api syntax
    – dimisjim
    Commented Apr 23, 2020 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.