forked from Wagmar/testing_with_spock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
220 lines (190 loc) · 7.39 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def createControl(String nome, String version){
println("inicio createControl")
def dir = new File("build/deploy/DEBIAN/")
if(!dir.exists()){
dir.mkdirs()
}
dir = new File(dir.absolutePath+"/control")
dir.write("Package: $nome\n")
dir.append("Version: $version\n")
dir.append("Architecture: all\n")
dir.append("Maintainer: Wagmar <[email protected]>\n")
dir.append("Depends: systemd, ca-certificates\n")
dir.append("Homepage: https://www.wagmar.com.br\n")
dir.append("Description: Aplicação $nome")
dir.createNewFile()
println("fim createControl")
}
def createFolder(String name, String folderName){
println("inicio createFolder")
def file = new File("build/deploy/wagmar/$folderName/$name")
if(!file.exists()){
file.mkdirs()
}
println("fim createFolder")
}
def createConf(String name){
println("inicio createConf")
def file = new File("build/deploy/etc/systemd/system")
if(!file.exists()){
file.mkdirs()
}
file = new File(file.absolutePath+"/$name"+".conf")
file.write("[Unit]\n")
file.append("Description=$name\n")
file.append("BindTo=network.target\n")
file.append("After=network.target\n")
file.append("Requires=network.target\n\n")
file.append("[Service]\n")
file.append("Type=simple\n")
file.append("Environment=LANG=en_US.UTF-8\n")
file.append("Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/\n")
file.append("UMask=0002\n")
file.append("User=msa\n")
file.append("Group=msa\n")
file.append("WorkingDirectory=/wagmar/msa/$name/\n")
file.append("StandardOutput=syslog\n")
file.append("StandardError=syslog\n")
file.append("SyslogIdentifier=$name\n")
file.append("ExecStart="+'$'+"JAVA_HOME/bin/java -Xms32m -Xmx128m -jar $name"+".jar\n")
file.append("Restart=on-failure\n")
file.append("[Install]\n")
file.append("WantedBy=multi-user.target\n")
file.createNewFile()
println("fim createConf")
}
def createPreInst(String name){
println("inicio createPretInst")
def file = new File("build/deploy/DEBIAN")
if(!file.exists()){
file.mkdirs()
}
file = new File(file.absolutePath+"/preinst")
file.write("#!/bin/bash\n")
file.append("stop servico com 2>/dev/null\n")
file.append("if [ \"\$(id wagmar.queiroga 2>/dev/null)\" ]; then \n")
file.append(" useradd -s /bin/false -d /wagmar/msa/$name --system $name \n")
file.append("fi\n")
file.createNewFile()
println("fim createPreInst")
}
def createPostInst(String name){
println("inicio createPostInst")
def file = new File("build/deploy/DEBIAN")
if(!file.exists()){
file.mkdirs()
}
file = new File(file.absolutePath+"/postinst")
file.write("#!/bin/bash\n")
file.append("chown -R $name:$name /wagmar/msa/$name \n")
file.append("chown -R $name:$name /wagmar/logs/$name \n")
file.append("systemctl reload $name \n")
file.append("systemctl enable $name \n")
file.append("systemctl start $name \n")
file.append("systemctl daemon-reload \n")
file.createNewFile()
println("fim createPostInst")
}
def createPostRM(String name){
println("inicio createPostRM")
def file = new File("build/deploy/DEBIAN")
if(!file.exists()){
file.mkdirs()
}
file = new File(file.absolutePath+"/postrm")
file.write("#!/bin/bash \n")
file.append("systemctl stop $name \n")
file.append("systemctl disable $name \n")
file.append("userdel $name \n")
file.createNewFile()
println("fim createPostRM")
}
pipeline {
agent any
tools {
jdk 'OpenJDK 1.8'
}
options {
timestamps()
gitLabConnection('gl-con1')
gitlabBuilds(builds: ['deploy'])
}
stages {
// stage('Build') {
//
// steps {
// gitlabCommitStatus(name: 'build') {
// sh './gradlew --info --stacktrace clean build'
// }
// }
//
// post {
// always {
// junit 'build/test-results/test/*.xml'
// }
// success {
// script {
// def props = readProperties file: 'build/resources/main/META-INF/build-info.properties'
// currentBuild.description = 'v' + props['build.version']
// }
// }
// }
// }
// stage('Code Coverage') {
// steps {
// gitlabCommitStatus(name: 'jacoco') {
// step([$class: 'JacocoPublisher', execPattern: 'build/jacoco/test.exec',
// classPattern: 'build/classes/java', sourcePattern: 'src/main/java'])
// }
// }
// }
// stage('Static Code Analysis') {
// steps {
// gitlabCommitStatus(name: 'sonarqube') {
// withSonarQubeEnv('SonarQube Server') {
// sh './gradlew --info --stacktrace sonarqube -x test'
// }
// timeout(time: 5, unit: 'MINUTES') {
// script {
// def qualitygate = waitForQualityGate()
// if (qualitygate.status != "OK") {
// error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
// }
// }
// }
// }
// }
// }
// stage('Publish') {
// steps {
// gitlabCommitStatus(name: 'publish') {
// withCredentials([usernamePassword(credentialsId: 'rctiReleasesRepo',
// usernameVariable: 'ORG_GRADLE_PROJECT_deployerUsername',
// passwordVariable: 'ORG_GRADLE_PROJECT_deployerPassword')]) {
// sh './gradlew --info --stacktrace publish -x jar'
// }
// }
// }
// }
stage('deploy') {
steps {
gitlabCommitStatus(name: 'deploy') {
script{
def props = readProperties file: 'build/resources/main/META-INF/build-info.properties'
def version = props['build.version']
def artifactName = props['build.name']
println("createControl")
createControl('teste', '1.0.0')
println("createConf")
createConf('teste')
println("createFolder")
createFolder('teste',"msa")
createFolder('teste',"logs")
sh "cp build/libs/rcserver* build/deploy/wagmar/msa/$artifactName"
}
}
}
}
}
}
// vim: syntax=groovy