-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
91 lines (87 loc) · 4.59 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
def remote = [name: env.BOT_NAME, host: env.BOT_HOST, allowAnyHosts: true]
pipeline {
agent any
parameters{
booleanParam(defaultValue: true, description: 'Deploy reporting-bot', name: 'enable_step_DEPLOY')
string(defaultValue: '', description: 'Build reporting-bot from version', trim: true, name: 'build_version')
}
options {
skipDefaultCheckout true
disableConcurrentBuilds()
timeout(time:10, unit: 'MINUTES')
timestamps()
buildDiscarder(logRotator(artifactDaysToKeepStr: '7', artifactNumToKeepStr: '10', daysToKeepStr: '7', numToKeepStr: '50'))
}
environment {
BUILDDIR = "/var/reporting-bot"
WORKDIR = "${BUILDDIR}/workdir"
TESTDIR = "${BUILDDIR}/testdir"
APPDIR = "reporting-bot"
APPNAME = "reporting-telegrambot.jar"
SPRING_PROFILE = "dev"
}
stages{
stage('Checkout') {
steps{
script{
withCredentials([sshUserPrivateKey(credentialsId: 'RepoBotHostDO-pk-Creds', keyFileVariable: 'USER_SECRET', usernameVariable: 'USER_LOGIN')]) {
remote.user = USER_LOGIN
remote.identityFile = USER_SECRET
sshCommand remote: remote, command: String.format('docker start reporting-bot; docker exec reporting-bot ps -ef | grep java | grep -v grep | awk \'{print \$2}\' | docker exec -i reporting-bot xargs -r kill; docker exec reporting-bot mkdir -p %s; docker exec reporting-bot rm -rf %s; docker exec reporting-bot mkdir %s; docker exec reporting-bot git clone --depth 1 --branch %s https://github.com/gameWizzards/reporting-bot.git %s;',
"$TESTDIR",
"$TESTDIR/$APPDIR/",
"$TESTDIR/$APPDIR/",
params.build_version,
"$TESTDIR/$APPDIR/")
}
}
}
}
stage('Unit_tests') {
steps {
script{
withCredentials([sshUserPrivateKey(credentialsId: 'RepoBotHostDO-pk-Creds', keyFileVariable: 'USER_SECRET', usernameVariable: 'USER_LOGIN')]) {
remote.user = USER_LOGIN
remote.identityFile = USER_SECRET
sshCommand remote: remote, command: String.format('docker exec reporting-bot mvn verify -f %s;',
"$TESTDIR/$APPDIR")
}
}
}
}
stage('Integration_tests') {
steps{
echo 'Here will be integration tests'
//sshCommand remote: remote, command: String.format('docker exec reporting-bot mvn verify -f %s',
//"$TESTDIR/$APPDIR")
}
}
stage('Deploy') {
when {
expression {
return params.enable_step_DEPLOY
}
}
steps{
script{
withCredentials([sshUserPrivateKey(credentialsId: 'RepoBotHostDO-pk-Creds', keyFileVariable: 'USER_SECRET', usernameVariable: 'USER_LOGIN')]) {
remote.user = USER_LOGIN
remote.identityFile = USER_SECRET
sshCommand remote: remote, command: String.format('docker exec reporting-bot mkdir -p %s; docker exec reporting-bot cp %s/target/%s %s; docker exec reporting-bot java -Dspring.profiles.active=%s -jar %s >/dev/null 2>&1 &',
"$WORKDIR",
"$TESTDIR/$APPDIR",
"$APPNAME",
"$WORKDIR/",
"$SPRING_PROFILE",
"$WORKDIR/$APPNAME")
}
}
}
}
}
post {
always {
telegramSend(message: "Job = ${JOB_NAME}. Status = ${currentBuild.getCurrentResult()}")
}
}
}