forked from paulphilip/pythoncode
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsPipelineECR
More file actions
39 lines (37 loc) · 1.49 KB
/
JenkinsPipelineECR
File metadata and controls
39 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
https://medium.com/@lilnya79/integrate-jenkins-with-amazon-ecr-4946ca5b86e1
pipeline {
agent any
environment {
AWS_REGION = 'us-east-2'
ECR_REPO = 'ecr-jenkins'
AWS_ACCOUNT_ID = '390403857742'
URL_REGISTRY = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
}
stages {
stage('Login') {
steps {
//sh 'aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 390403857742.dkr.ecr.us-east-2.amazonaws.com'
sh 'docker tag ecrimage:v1 390403857742.dkr.ecr.us-east-2.amazonaws.com/ecr-jenkins:latest'
sh 'echo "Login Success"'
}
}
stage('Tag') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'ecr-cred', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY')]) {
// Login to ECR
sh "aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${URL_REGISTRY}"
// Push Docker image to ECR
sh "docker push ${URL_REGISTRY}/$ECR_REPO:latest"
}
}
}
}
stage('List') {
steps {
//sh 'docker push 390403857742.dkr.ecr.us-east-2.amazonaws.com/ecr-jenkins:latest'
sh 'echo "List Success"'
}
}
}
}