forked from indigo-dc/ci-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
82 lines (72 loc) · 2.65 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
// vim: filetype=groovy
pipeline {
agent {
label 'docker'
}
stages {
stage("Docker Variable initialization") {
environment {
AI4OS_REGISTRY_CREDENTIALS = credentials('AIOS-registry-credentials')
}
steps {
script {
withFolderProperties{
docker_registry = env.AI4OS_REGISTRY
}
docker_ids = []
docker_registry_credentials = env.AI4OS_REGISTRY_CREDENTIALS
}
}
}
stage('Build docker images') {
steps {
// Iterate over the directories and subdirectories. Join directory and subdirectory together to create the image names
script {
dirs = sh (script: 'find * -name Dockerfile -printf "%h\n" | sort | uniq',
returnStdout: true).split("\n")
docker.withRegistry(docker_registry, docker_registry_credentials) {
for (dir in dirs) {
def image = dir.replace("/", "")
image = "ai4os-hub/ci-images:${image}"
def dockerfile = "${dir}/Dockerfile"
echo "Building image: ${image}"
image_id = docker.build(image, "--no-cache --force-rm -f ${dockerfile} ${dir}")
docker_ids.add(image)
}
}
}
}
}
stage('AI4OS Hub Docker delivery to registry') {
when {
expression {
docker_ids.size() > 0
}
expression {
env.BRANCH_NAME == 'master'
}
}
steps {
script {
docker.withRegistry(docker_registry, docker_registry_credentials) {
docker_ids.each {
println "Pushing image: ${it}"
docker.image(it).push()
}
}
}
}
}
}
post {
// Clean after build
always {
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
}