-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
99 lines (89 loc) · 2.74 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
pipeline {
agent any
environment{
docker=credentials('gitlab-token')
IMAGE_NAME='registry.gitlab.com/kumail.r7/slack-docker'
}
stages {
stage ("Checkout from git") {
agent {
label "agent1"
}
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlab-token', url: 'https://gitlab.com/kumail.r7/slack-docker.git']])
}
}
stage ("Build the image") {
agent {
label "agent1"
}
steps{
sh "docker build -t ${IMAGE_NAME}:$BUILD_NUMBER ."
}
}
stage ("Container Resgistry login") {
agent {
label "agent1"
}
steps{
sh "echo $docker_PSW | docker login registry.gitlab.com -u $docker_USR --password-stdin"
}
}
stage ("Scan the image") {
agent {
label "agent1"
}
steps {
sh "trivy image ${IMAGE_NAME}:$BUILD_NUMBER > scanning.txt "
}
}
stage ("push the image") {
agent {
label "agent1"
}
steps {
sh "docker push ${IMAGE_NAME}:$BUILD_NUMBER"
}
}
stage ("Delete the image") {
agent {
label "agent1"
}
steps {
sh "docker rmi -f ${IMAGE_NAME}:$BUILD_NUMBER"
}
}
stage("Checkout only docker-compose file"){
agent {
label "deploy-server"
}
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlab-token', url: 'https://gitlab.com/kumail.r7/slack-docker.git']])
}
}
stage ("Container Resgistry login on deploy-server") {
agent {
label "deploy-server"
}
steps{
sh "echo $docker_PSW | docker login registry.gitlab.com -u $docker_USR --password-stdin"
}
}
stage ("pulling the image on deploy-server") {
agent {
label "deploy-server"
}
steps {
sh "docker pull registry.gitlab.com/kumail.r7/slack-docker:$BUILD_NUMBER"
}
}
stage ("Deploying of the image") {
agent {
label "deploy-server"
}
steps {
sh "docker compose up -d "
}
}
}
}