-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
181 lines (167 loc) · 4.97 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
//
// This Jenkinsfile builds the ontology-publisher image, runs a test and when the test passes it publishes the image
// to the Docker Registry
//
def app
pipeline {
agent none
environment {
LC_ALL = 'en_US.UTF-8'
LANG = 'en_US.UTF-8'
LANGUAGE = 'en_US.UTF-8'
ONTOLOGY_FAMILY = 'fibo'
FIBO_BRANCH = 'master'
ONTOLOGY_BUILDER_IMAGE = 'edmcouncil/ontology-publisher'
REGISTRY = "https://registry.hub.docker.com"
}
options {
buildDiscarder(
logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')
)
//
// We let each stage running on each jenkins slave / agent decide what to check out or not
//
skipDefaultCheckout()
//
// Skip stages once the build status has gone to UNSTABLE.
//
skipStagesAfterUnstable()
//
// There must be SOME limit, if it hangs or whatever then that's a bug and therefore cancel the job.
//
timeout(time: 23, unit: 'HOURS')
//
// Prepend all console output generated by the Pipeline run with the time at which the line was emitted
//
//timestamps()
ansiColor('xterm')
}
stages {
stage('Prepare') {
agent {
label 'docker'
}
environment {
PATH = "$PATH:/usr/bin"
}
steps {
echo 'PATH=' + env.PATH
echo 'ONTOLOGY_FAMILY=' + env.ONTOLOGY_FAMILY
echo "Cleaning workspace:"
sh 'rm -rf ${WORKSPACE}/* || true'
echo "Done cleaning"
//
// Check out this repo in the publisher directory so that we're not copying the ontology-repo into
// the image. We're building the image from the publisher directory.
//
dir('publisher') {
checkout scm
script {
env.GIT_HASH_BUILDER = sh(
script: "#!/bin/sh -e\ngit show --oneline | head -1 | cut -d' ' -f1",
returnStdout: true
).trim()
}
echo "GIT_HASH_BUILDER=>${env.GIT_HASH_BUILDER}"
}
dir('fibo') {
checkout changelog: false, poll: false, scm: [
$class: 'GitSCM',
branches: [
[name: "*/${env.FIBO_BRANCH}"]
],
doGenerateSubmoduleConfigurations: false,
extensions: [
[
$class: 'CheckoutOption',
timeout: 1
], [
$class: 'CloneOption',
noTags: true,
reference: '',
shallow: true,
timeout: 1
], [
$class: 'PruneStaleBranch'
], [
$class: 'IgnoreNotifyCommit'
]
],
submoduleCfg: [],
userRemoteConfigs: [
[
credentialsId: '50cac519-d41c-4765-8563-c43b7f55c877',
url: 'https://github.com/edmcouncil/fibo.git'
]
]
]
script {
env.GIT_HASH_ONTOLOGIES = sh(
script: "#!/bin/sh -e\ngit show --oneline | head -1 | cut -d' ' -f1",
returnStdout: true
).trim()
}
echo 'Checked out fibo repo'
echo "GIT_HASH_ONTOLOGIES=>${env.GIT_HASH_ONTOLOGIES}"
}
}
} // end of stage 'Prepare'
stage('Build Image 1') {
agent {
label 'docker'
}
steps {
sh "docker build --tag ${env.ONTOLOGY_BUILDER_IMAGE}:${env.GIT_HASH_BUILDER} ."
}
}
stage('Build image') {
agent {
dockerfile {
filename 'Dockerfile'
dir 'publisher'
additionalBuildArgs '--pull --tag ${ONTOLOGY_BUILDER_IMAGE}:${GIT_HASH_BUILDER} --build-arg ONTPUB_FAMILY=${ONTOLOGY_FAMILY}'
args '-u 0:0 ' +
'--mount type=bind,source=${WORKSPACE}/fibo,target=/input/fibo,readonly,consistency=cached ' +
'-w /publisher'
}
}
environment {
PATH = "$PATH:/usr/bin"
}
//
// Everything that happens below is done inside the container
//
steps {
sh 'cd /publisher && ./publish.sh --help'
}
}
stage('Publish Image') {
agent {
label 'docker'
}
when {
branch 'master'
}
environment {
PATH = "$PATH:/usr/bin"
}
steps {
echo "Now publish the image ${env.ONTOLOGY_BUILDER_IMAGE}"
withDockerRegistry([
credentialsId: 'docker-hub-credentials',
url: ''
]) {
sh "export"
sh "docker push --help"
sh "echo 1 ${env.ONTOLOGY_BUILDER_IMAGE}"
sh 'echo 2 ${env.ONTOLOGY_BUILDER_IMAGE}'
sh "echo 3 ${ONTOLOGY_BUILDER_IMAGE}"
sh 'echo 4 ${ONTOLOGY_BUILDER_IMAGE}'
sh "echo 5 \${ONTOLOGY_BUILDER_IMAGE}"
sh "docker push ${env.ONTOLOGY_BUILDER_IMAGE}:${env.GIT_HASH_BUILDER}"
sh "docker push ${env.ONTOLOGY_BUILDER_IMAGE}:latest"
}
}
}
}
}