Reputation: 659
I have a existing Jenkins pipeline job which build docker image and push it to AWS ECR repository.
We are not using ECS in our shop.
I want to create a jenkins pipeline job which will take this latest ECR image form repository and put in an Existing EC2 instance,create container from that image and open on some port.
Need any sample pipeline job to achieve this,any reference will also help.
Upvotes: 3
Views: 4523
Reputation: 3029
This is how you can pull docker image from ECR using Jenkins pipeline:
pipeline
{
options
{
buildDiscarder(logRotator(numToKeepStr: '3'))
}
agent any
environment
{
PROJECT = 'tap_sample'
ECRURL = 'http://999999999999.dkr.ecr.eu-central-1.amazonaws.com'
ECRCRED = 'ecr:eu-central-1:tap_ecr'
}
stages
{
stage('Docker image pull')
{
steps
{
script
{
sh("eval \$(aws ecr get-login --no-include-email | sed 's|https://||')")
docker.withRegistry(ECRURL, ECRCRED)
{
docker.image(PROJECT).pull()
}
}
}
}
}
}
The example is taken from this amazing article.
Upvotes: 1