-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
156 lines (146 loc) · 5.07 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
pipeline {
agent any
parameters {
booleanParam(
name: 'DEPLOY_IN_PROD',
description: 'deploy in production ?',
defaultValue: false,
)
}
stages {
stage('checkout') {
steps {
cleanWs()
deleteDir()
checkout scm
}
}
stage('install compose') {
steps {
sh '''
#les 3 prochaine lignes doivent etre conditionnel ou alors les faire lors de la constrution de l\'image jenkins
apt-get install sudo -y
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version'''
}
}
stage('maven install and docker-compose up (deploy into tomcat)') {
steps {
withMaven(maven: 'maven3') {
script {
echo "deploying in prod : ${params.DEPLOY_IN_PROD}"
if (env.BRANCH_NAME == 'dev') {
sh '''
mvn clean install package -Dmaven.test.skip=true -Pdev
ls -a
'''
sh '''
docker-compose -f docker-compose-dev.yml --env-file ./environments/.env.dev up -d --no-deps --build --force-recreate dev-api
'''
} else if(env.BRANCH_NAME == 'master'){
if (params.DEPLOY_IN_PROD) {
pom = readMavenPom file: 'pom.xml'
echo "deploying in prod : ${params.DEPLOY_IN_PROD}"
sh "curl -H 'Accept: application/zip' --user admin:cYs3kfqCN25Xdu https://nexus.dsp4-5archio19-ah-je-gh-yb.fr/repository/theTipTop_microservice/com/dsp/theTipTop/${pom.version}/theTipTop-${pom.version}.war -o theTipTop.war"
sh 'docker-compose -f docker-compose.yml -f docker-compose-prod.yml --env-file ./environments/.env.prod up -d --no-deps --build --force-recreate prod-api'
} else {
sh '''
mvn clean install package -Dmaven.test.skip=true -Pprod
ls -a
'''
sh '''
docker-compose -f docker-compose.yml -f docker-compose-stage.yml --env-file ./environments/.env.stage up -d --no-deps --build --force-recreate stage-api
'''
}
}
}
}
}
}
stage('tests') {
parallel {
stage('test JUnit') {
steps {
withMaven(maven: 'maven3') {
sh 'mvn test -Pprod'
}
}
post {
always {
junit 'target/surefire-reports/**/*.xml'
}
}
}
stage('build && SonarQube analysis') {
steps {
withSonarQubeEnv(installationName: 'sonarqube', credentialsId: 'tokenB') {
withMaven(maven: 'maven3') {
sh 'mvn sonar:sonar'
}
}
}
}
}
}
stage('Deploy Artifact To Nexus') {
when {
allOf {
branch 'master'
expression { !params.DEPLOY_IN_PROD }
}
}
steps {
sh '''cd target/
ls -a'''
script {
pom = readMavenPom file: 'pom.xml'
// Find built artifact under target folder
filesByGlob = './'
// Print some info from the artifact found
// echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
// Extract the path from the File found
artifactPath = './'
// Assign to a boolean response verifying If the artifact name exists
artifactExists = fileExists artifactPath
if (artifactExists) {
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'https',
nexusUrl: 'nexus.dsp4-5archio19-ah-je-gh-yb.fr',
groupId: pom.groupId,
version: pom.version,
repository: 'theTipTop_microservice/',
credentialsId: 'nexus3',
artifacts: [
// Artifact generated such as .jar, .ear and .war files.
[
artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging
],
// Lets upload the pom.xml file for additional information for Transitive dependencies
[
artifactId: pom.artifactId,
classifier: '',
file: 'pom.xml',
type: 'pom'
],
[
artifactId: pom.artifactId,
classifier: '',
file: './target/theTipTop.war',
type: 'war'
]
]
)
}
else {
error "*** File: ${artifactPath}, could not be found"
}
}
}
}
}
}