-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathJenkinsfile
More file actions
132 lines (126 loc) · 3.88 KB
/
Jenkinsfile
File metadata and controls
132 lines (126 loc) · 3.88 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def notifySlack(String buildStatus = 'STARTED',String security = 'ANALYSING' ) {
buildStatus = buildStatus ?: 'SUCCESS'
def color
if (buildStatus == 'STARTED') {
color = '#D4DADF'
} else if (buildStatus == 'SUCCESS') {
color = '#BDFFC3'
} else if (buildStatus == 'UNSTABLE') {
color = '#FFFE89'
} else {
color = '#FF9FA1'
}
def msg = "${buildStatus}:`${env.JOB_NAME}` #${env.BUILD_NUMBER}\nSecurity: `${security}`\nUrl: ${RUN_DISPLAY_URL}\nChanges: ${RUN_CHANGES_DISPLAY_URL}"
slackSend(color: color, message: msg, channel: 'tempusbuild', botUser: true)
}
pipeline {
options {
timeout(time: 2, unit: 'HOURS')
}
agent {
docker {
image 'hashmapinc/tempusbuild:java-11-secret-scan'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages {
stage('Secret Scan') {
steps {
notifySlack()
script{
securitystatus = "BREACHED"
}
sh '''
git secrets --register-aws
git-secrets --scan
'''
}
}
stage('Initialize') {
steps {
script{
securitystatus = "SECURE"
}
sh 'echo $USER'
sh '''echo PATH = ${PATH}
echo M2_HOME = ${M2_HOME}
mvn clean
mvn validate'''
}
}
stage('Build') {
steps {
sh 'mvn -Dmaven.test.failure.ignore=true -DskipITs org.jacoco:jacoco-maven-plugin:prepare-agent install'
}
}
stage('Integration Tests') {
steps {
sh 'mvn failsafe:integration-test'
sh 'mvn failsafe:verify'
}
}
stage('SonarQube analysis') {
steps {
withSonarQubeEnv('SonarCloud') {
sh 'mvn -Dsonar.organization=hashmapinc-github -Dsonar.branch.name=$BRANCH_NAME sonar:sonar'
}
}
}
stage('Report and Archive') {
steps {
junit '**/target/surefire-reports/**/*.xml,**/target/failsafe-reports/**/*.xml'
archiveArtifacts 'application/target/*.jar,application/target/*.deb,application/target/*.zip,application/target/*.rpm'
}
}
stage('Deploy Artifacts') {
when {
branch 'dev'
}
steps {
configFileProvider([configFile(fileId: 'global-maven-config', variable: 'MAVEN_SETTINGS_XML')]) {
sh 'mvn -s $MAVEN_SETTINGS_XML -Dmaven.test.failure.ignore=true -DskipITs -DskipTests deploy'
}
}
}
stage('Publish Image') {
when {
branch 'dev'
}
steps {
sh '''cp $WORKSPACE/application/target/tempus.deb $WORKSPACE/docker/tb/tempus.deb
cp $WORKSPACE/application/target/tempus.deb $WORKSPACE/docker/database-setup/tempus.deb'''
withCredentials(bindings: [usernamePassword(credentialsId: 'docker_hub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'sudo docker login -u $USERNAME -p $PASSWORD'
}
sh '''sudo docker build $WORKSPACE/docker/tb/ -t hashmapinc/tempus:dev
sudo docker build $WORKSPACE/docker/database-setup/ -t hashmapinc/database-setup:dev'''
sh '''sudo docker push hashmapinc/tempus:dev
sudo docker push hashmapinc/database-setup:dev
'''
}
}
stage('Publish Master Image') {
when {
branch 'master'
}
steps {
withCredentials(bindings: [usernamePassword(credentialsId: 'docker_hub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'sudo docker login -u $USERNAME -p $PASSWORD'
}
sh '''cd ./docker/tb/
make push'''
}
}
}
post {
always {
sh 'chmod -R 777 .'
}
success {
notifySlack(currentBuild.result,'SECURE')
}
failure {
notifySlack(currentBuild.result,securitystatus)
}
}
}