Amazon ECR is Amazon's container registry service and is a convenient place to store Docker images. If you're already using AWS, it's pretty nice to use as it has free data transfer and it requires minimal setup.
However, using it with Jenkins is deceptively complicated. You may think the Amazon ECR Jenkins Plugin all you need, but if you're not using Jenkins Pipelines, you're on the wrong track-- it doesn't work! You will get an error that looks something like this:
[myservice] $ docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/myservice:latest
The push refers to a repository [123456789.dkr.ecr.us-east-1.amazonaws.com/myservice]
denied: Your Authorization Token has expired. Please run 'aws ecr get-login' to fetch a new one.
Build step 'Docker Build and Publish' marked build as failure
The easiest solution I've found is to set up the Amazon ECR Credential Helper, of which the documentation is pretty straightforward to follow to set up.
When doing this, make sure your credential file is named
~/.aws/credentials. If you use
config it won't work.
Note that you don't need to use the Cloudbees Docker Build And Push plugin anymore if you use this. Just use plain ol'
docker build and
This blog post didn't really go over any of the details, but if you run into this issue, this is how I solved it!