pipeline {
agent any
environment {
AWS_REGION = 'eu-west-1'
GITCOMMIT="${env.GIT_COMMIT}"
}
// options {
// ansiColor('xterm')
// }
stages {
stage('docker build and push to ecr') {
steps {
sh(label: 'ECR login and docker push', script:
'''
#!/bin/bash
echo "Authenticate with ECR"
set +x # Don't echo credentials from the login command!
echo "Building New ECR Image"
eval $(aws ecr get-login --region "$AWS_REGION" --no-include-email)
# Enable Debug and Exit immediately
set -xe
docker build -t 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:${GITCOMMIT} .
#two push one for master tag other is git commit ID
docker push 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:${GITCOMMIT}
docker tag 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:${GITCOMMIT} 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:latest
docker push 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:latest
'''.stripIndent())
}
}
}
Forked from ismailyenigul/jenkins-ecr-push-with-ec2-iam-role-permission.md
Created
February 24, 2022 10:10
-
-
Save Atadzhan/b1a918596ac406cccc9a32cb9ab8d816 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment