forked from underworldcode/underworld2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsfile
112 lines (102 loc) · 2.85 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
#!groovy
/* A Jenkins "Declarative" Pipeline file.
See http://115.146.85.138:32779
*/
pipeline {
agent {
// special label to jenkins config. See http://115.146.85.138:32779/computer/
label 'slave'
}
environment {
// define environment variable active within pipeline
CNAME = "${env.GIT_COMMIT}"
INAME = "${CNAME}"+"-image"
}
options {
timeout(time: 2, unit: 'HOURS')
disableConcurrentBuilds()
timestamps()
}
stages {
// Build stage: compile the code
stage('Build Image') {
steps {
// print environment variables
sh 'printenv'
// build the docker
sh 'docker build --pull --rm --force-rm --no-cache -t ${INAME} -f ./docs/development/docker/underworld2/Dockerfile .'
}
}
// Test stage: runs the basic tests
stage('Basic Tests') {
// Run inside docker continer created
steps {
sh '''
docker run -i -w /home/jovyan/development --name ${CNAME} ${INAME} ./test_suite.sh
'''
}
post {
always {
sh '''
docker cp ${CNAME}:/home/jovyan/development/testResults ./testResults
'''
}
}
}
// Run image_test.py separately, if it fails mark build 'UNSTABLE'
/*stage('image_tests') {
steps {
script {
try{
dir("./utils") {
sh './run_tests.py ../doc/test/image_tests.py'
}
}
catch(exc) {
currentBuild.result = 'UNSTABLE'
echo 'The image test phase failed. Not critical'
}
}
}
}*/
}
/* For post build analysis */
post {
failure {
// notify users when the Pipeline fails
emailext (
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}",
// mimeType: 'text/html',
to: '[email protected]'
)
}
unstable {
// notify users when the Pipeline fails
emailext (
subject: "Unstable Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is unstable with ${env.BUILD_URL}",
// mimeType: 'text/html',
to: '[email protected]'
)
}
success {
script {
if (currentBuild.previousBuild != null && currentBuild.previousBuild.result != 'SUCCESS') {
emailext (
subject: "Back to normal: ${currentBuild.fullDisplayName}",
body: "Project is back to normal",
// mimeType: 'text/html',
to: '[email protected]'
)
}
}
}
cleanup {
// force container removal
sh 'docker rm -f ${CNAME}'
sh 'docker rmi ${INAME}'
sh 'docker rmi $(docker images -f "dangling=true" -q)'
}
}
}