forked from indigo-iam/iam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
137 lines (114 loc) · 3.78 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
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
133
134
135
136
137
#!/usr/bin/env groovy
def maybeArchiveJUnitReports(){
def hasJunitReports = fileExists 'iam-login-service/target/surefire-reports'
if (hasJunitReports) {
junit '**/target/surefire-reports/TEST-*.xml'
}
}
def maybeArchiveJUnitReportsWithJacoco(){
def hasJunitReports = fileExists 'iam-login-service/target/surefire-reports'
if (hasJunitReports) {
junit '**/target/surefire-reports/TEST-*.xml'
step( [ $class: 'JacocoPublisher' ] )
}
}
pipeline {
agent { label 'java17' }
options {
ansiColor('xterm')
buildDiscarder(logRotator(numToKeepStr: '5'))
skipDefaultCheckout()
timeout(time: 1, unit: 'HOURS')
timestamps()
}
parameters {
booleanParam(name: 'SKIP_TESTS', defaultValue: false, description: 'Skip tests')
booleanParam(name: 'RUN_SONAR', defaultValue: false, description: 'Runs SONAR analysis')
booleanParam(name: 'BUILD_DOCKER_IMAGES', defaultValue: false, description: 'Build docker images')
booleanParam(name: 'PUSH_TO_DOCKERHUB', defaultValue: false, description: 'Push to Dockerhub')
}
triggers { cron('@daily') }
environment {
DOCKER_REGISTRY_HOST = "${env.DOCKER_REGISTRY_HOST}"
SONAR_USER_HOME = "${env.WORKSPACE}/.sonar"
SONAR_ORGANIZATION = "indigo-iam"
SONAR_HOST_URL = "https://sonarcloud.io"
SONAR_PROJECT_KEY = "indigo-iam_iam"
SONAR_TOKEN = credentials('sonar_token_vianello')
}
stages {
stage('build, test, package'){
stages {
stage('checkout') {
steps {
deleteDir()
checkout scm
stash name: 'code', useDefaultExcludes: false
}
}
stage('license-check') {
steps {
sh 'mvn -B license:check'
}
}
stage('compile') {
steps {
sh 'mvn -B compile'
}
}
stage('Tests (no Sonar analysis)') {
when{
allOf{
not {
expression { return params.RUN_SONAR }
}
not {
expression { return params.SKIP_TESTS }
}
}
}
steps {
sh 'mvn -B test'
}
post {
always {
script {
maybeArchiveJUnitReports()
}
}
}
}
stage('Sonar analysis') {
when {
expression {
return params.RUN_SONAR
}
}
steps {
sh "mvn -B -U install sonar:sonar -Dsonar.projectKey=${env.SONAR_PROJECT_KEY} -Dsonar.organization=${env.SONAR_ORGANIZATION} -Dsonar.login=${env.SONAR_TOKEN} -Dsonar.scm.provider=git -Dsonar.host.url=${env.SONAR_HOST_URL}"
}
}
stage('deploy & package') {
steps {
sh 'mvn -B -DskipTests=true clean deploy package'
archiveArtifacts 'iam-login-service/target/iam-login-service.war'
archiveArtifacts 'iam-login-service/target/classes/iam.version.properties'
archiveArtifacts 'iam-test-client/target/iam-test-client.jar'
stash includes: 'iam-login-service/target/iam-login-service.war,iam-login-service/target/classes/iam.version.properties,iam-test-client/target/iam-test-client.jar', name: 'iam-artifacts'
}
}
}
}
}
post {
success {
slackSend channel: "#iam", color: 'good', message: "${env.JOB_NAME} - #${env.BUILD_NUMBER} Success (<${env.BUILD_URL}|Open>)"
}
unstable {
slackSend channel: "#iam", color: 'danger', message: "${env.JOB_NAME} - #${env.BUILD_NUMBER} Unstable (<${env.BUILD_URL}|Open>)"
}
failure {
slackSend channel: "#iam", color: 'danger', message: "${env.JOB_NAME} - #${env.BUILD_NUMBER} Failure (<${env.BUILD_URL}|Open>)"
}
}
}