-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
79 lines (78 loc) · 2.53 KB
/
Jenkinsfile
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
pipeline {
agent {
label 'master'
}
environment {
AWS_ACCOUNT_ID="aws-credentials"
AWS_DEFAULT_REGION="eu-central-1"
IMAGE_REPO_NAME="my-nginx"
IMAGE_TAG="v2"
REPOSITORY_URI = "064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr"
}
stages {
stage('Git-Checkout') {
agent {
label 'master'
}
steps {
echo "Checking out from Git Repo";
git branch: 'main', url: 'https://github.com/Levi-Michael/Web-CI-CD.git';
}
}
stage('Build-Image') {
agent {
label 'master'
}
steps {
script{
sh "docker build -t ${IMAGE_REPO_NAME}:${IMAGE_TAG} ."
sh "docker tag ${IMAGE_REPO_NAME}:${IMAGE_TAG} 064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr:${IMAGE_REPO_NAME}"
}
}
}
stage('Push-To-ECR') {
agent {
label 'master'
}
steps {
script{
docker.withRegistry("https://064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr", "ecr:eu-central-1:aws-credentials") {
sh "docker push 064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr:${IMAGE_REPO_NAME}"
}
}
}
}
stage('Pull-From-ECR') {
agent {
label 'docker'
}
steps {
echo "Deploying to Stage Environment for more tests!";
script{
docker.withRegistry("https://064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr", "ecr:eu-central-1:aws-credentials") {
"docker pull 064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr:${IMAGE_REPO_NAME}"
}
}
}
}
stage('Run-Image') {
agent {
label 'docker'
}
steps {
echo "Running web server!";
sh 'docker kill $(docker ps -q)'
sh "docker run -d -p 80:80 064055967665.dkr.ecr.eu-central-1.amazonaws.com/terraformecr:${IMAGE_REPO_NAME}"
}
}
stage('Cleaning-master-images') {
agent {
label 'master'
}
steps {
echo "Cleaning images...";
sh 'docker rmi -f $(docker images -a -q)'
}
}
}
}