File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ https://medium.com/@lilnya79/integrate-jenkins-with-amazon-ecr-4946ca5b86e1
2+
3+ pipeline {
4+ agent any
5+ environment {
6+ AWS_REGION = 'us-east-2'
7+ ECR_REPO = 'ecr-jenkins'
8+ AWS_ACCOUNT_ID = '390403857742'
9+ URL_REGISTRY = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
10+ }
11+ stages {
12+ stage('Login') {
13+ steps {
14+ //sh 'aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 390403857742.dkr.ecr.us-east-2.amazonaws.com'
15+ sh 'docker tag ecrimage:v1 390403857742.dkr.ecr.us-east-2.amazonaws.com/ecr-jenkins:latest'
16+ sh 'echo "Login Success"'
17+ }
18+ }
19+ stage('Tag') {
20+ steps {
21+ script {
22+ withCredentials([usernamePassword(credentialsId: 'ecr-cred', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY')]) {
23+ // Login to ECR
24+ sh "aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${URL_REGISTRY}"
25+
26+ // Push Docker image to ECR
27+ sh "docker push ${URL_REGISTRY}/$ECR_REPO:latest"
28+ }
29+ }
30+ }
31+ }
32+ stage('List') {
33+ steps {
34+ //sh 'docker push 390403857742.dkr.ecr.us-east-2.amazonaws.com/ecr-jenkins:latest'
35+ sh 'echo "List Success"'
36+ }
37+ }
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments