-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
65 lines (57 loc) · 1.86 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
pipeline {
agent any
tools {
maven 'maven-3.9.6'
}
stages {
stage('Code Analysis') {
steps {
script {
def scanner = tool 'scanner-5.0.1'
echo "${scanner}"
withSonarQubeEnv('MySonar') {
sh "${scanner}/bin/sonar-scanner"
}
}
}
}
stage('Unit Tests') {
steps {
sh 'mvn test'
}
}
stage('Build Artifact') {
steps {
sh 'mvn clean package'
}
}
stage('Build Image') {
steps {
sh 'docker build -t noumendarryl/helloworld:1.${BUILD_NUMBER} . '
sh 'docker build -t noumendarryl/helloworld:latest . '
}
}
stage('Push on DockerHub') {
steps {
withCredentials([usernamePassword(credentialsId: 'DOCKER_ID', passwordVariable: 'DOCKER_PWD', usernameVariable: 'DOCKER_USERNAME')]) {
sh 'docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PWD}'
}
sh 'docker push noumendarryl/helloworld:1.${BUILD_NUMBER}'
sh 'docker push noumendarryl/helloworld:latest'
}
}
stage('Run Container') {
steps {
sh 'docker run noumendarryl/helloworld:latest'
}
}
stage('Email Notification') {
steps {
mail body: "$JOB_NAME - BUILD # $BUILD_NUMBER - SUCCESS : Check console output at $BUILD_URL to view results. Please note this is an automated email.",
subject: "$JOB_NAME - BUILD # $BUILD_NUMBER - SUCCESS !",
from: '[email protected]',
to: '[email protected]'
}
}
}
}