forked from 1001genomes/AraGWAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
141 lines (123 loc) · 4.53 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
#!/usr/bin/env groovy
/**
* build / test pipeline for AraGWAS
*/
pipeline {
agent any
stages {
// global checkout needed for Docker setup
stage('checkout') {
steps {
checkout scm
}
}
// prepare the dockers: testing env
stage('test') {
steps {
script {
// build ui docker image to compile javascript
def ui_img = docker.build("aragwas_ui","aragwas_ui")
ui_img.inside('-u root') {
sh """
cd aragwas_ui
ln -s /srv/aragwas_ui/node_modules/ || true
npm run build
rm node_modules
"""
}
//ui_img.run('-a -v $WORKSPACE/dist:/srv/aragwas_server/gwasdb')
//sh 'cp -r dist/* $WORKSPACE/aragwas_server/gwasdb/'
//FIXME this in try-catch and clean shutdown of db_cont
def app_img = docker.build("aragwas","aragwas_server")
// link app container to db container, expose platinum test config path
app_img.inside() {
// run the behave tests
echo "running tests"
sh returnStatus: true, script: "cd /srv/web/ && py.test -ra -p no:cacheprovider --junitxml ${env.WORKSPACE}/TESTS-aragwas.xml"
}
// collect unit test results
junit "TESTS-aragwas.xml"
}
}
}
// not _really_ deploy, but push to local registry
stage('deploy') {
when{
branch 'master'
}
steps {
script {
sh 'sh write_version.sh'
//FIXME leaking local infra details
docker.withRegistry('https://docker.sci.gmi.oeaw.ac.at', 'platinum-docker-registry') {
// push DB docker img to registry
def server_img = docker.build("docker.sci.gmi.oeaw.ac.at/nordborg/aragwas", "aragwas_server")
server_img.push('testing')
sshagent(['801dbf20-4259-4d3b-8948-e84fe1b52c7f']) {
env.DEPLOY_HOST = 'aragwas.sci.gmi.oeaw.ac.at'
sh '''
scp -o StrictHostKeyChecking=no aragwas_server/docker-compose.yml root@$DEPLOY_HOST:/root/
ssh -o StrictHostKeyChecking=no root@$DEPLOY_HOST "cd /root && docker-compose pull && docker-compose up -d"
'''
}
}
}
}
}
// in the future: conditional deploy?
} //stages
// post block is executed after all the stages/steps in the pipeline
post {
always {
// notify build results, see https://jenkins.io/blog/2016/07/18/pipline-notifications/
notifyBuild(currentBuild.result)
}
changed {
echo "build changed"
}
aborted {
echo "build aborted"
}
failure {
echo "build failed"
}
success {
echo "build is success"
}
unstable {
echo "build is unstable"
}
}
}
// send global slack notification, but fail silently if this is not possible, i.e. slack integration is not installed
def notifyBuild(String buildStatus) {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESS'
if (buildStatus == 'STARTED' || buildStatus == 'CHANGED' || buildStatus == 'UNSTABLE') {
color = 'YELLOW'
colorCode = '#DDDD00'
}
else if (buildStatus == 'SUCCESS') {
color = 'GREEN'
colorCode = '#00DD00'
}
else {
// FAILURE or UNSTABLE
color = 'RED'
colorCode = '#DD0000'
}
def message = "${buildStatus}: Job <${env.BUILD_URL}|${env.JOB_NAME} #${env.BUILD_NUMBER}>"
/* we could add blame to the slack message ;) but it's visible on the build details anyway
if (buildStatus == 'FAILURE') {
def changes_by = sh 'git --no-pager log -1 --format=%an'
message = "${buildStatus}: Job <${env.BUILD_URL}|${env.JOB_NAME} #${env.BUILD_NUMBER}> caused by ${changes_by}"
}
*/
// send gracefully
try {
slackSend (color: colorCode, message: "${message}")
}
catch (e) {
echo "failed to send notification: ${e}"
}
}