-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
83 lines (78 loc) · 2.62 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
pipeline {
agent any
triggers {
pollSCM('H/5 * * * *')
}
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhubconfig')
IMAGE_NAME_SERVER = 'hanineguesmi/mern-server'
IMAGE_NAME_CLIENT = 'hanineguesmi/mern-client'
IMAGE_TAG = 'latest'
}
stages {
stage ('Checkout') {
steps {
git branch: 'main',
url: '[email protected]:haninhn/jenkisTp3.git',
credentialsId: 'id_ed25519'
}
}
stage('Build Server Image') {
steps {
dir('server') {
script {
dockerImageServer = docker.build("${IMAGE_NAME_SERVER}")
}
}
}
}
stage('Build Client Image') {
steps {
dir('client') {
script {
dockerImageClient = docker.build("${IMAGE_NAME_CLIENT}")
}
}
}
}
stage('Scan Server Image') {
steps {
script {
retry(4) {
sh """
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \\
aquasec/trivy:latest image --exit-code 0 --severity LOW,MEDIUM,HIGH,CRITICAL \\
${IMAGE_NAME_SERVER}
"""
}
}
}
}
stage('Scan Client Image') {
steps {
script {
retry(4) {
sh """
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \\
aquasec/trivy:latest image --exit-code 0 --severity LOW,MEDIUM,HIGH,CRITICAL \\
${IMAGE_NAME_CLIENT}
"""
}
}
}
}
stage('Push Images to Docker Hub') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'dockerhubconfig', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_TOKEN')]) {
sh '''
echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin
docker push ${IMAGE_NAME_SERVER}
docker push ${IMAGE_NAME_CLIENT}
'''
}
}
}
}
}
}