-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
79 lines (67 loc) · 1.61 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
def packer_dir = "/mnt/nfs/packer"
def packer_tpl = ["qemu-ubuntu-bionic", "qemu-ubuntu-xenial", "qemu-ubuntu-trusty"]
def http_proxy = "http://192.168.255.14:3128"
def parse_json(json) {
return new groovy.json.JsonSlurper().parseText(json)
}
def cleanup_artifacts() {
sh "rm -rf packer-artifacts"
}
@NonCPS
def list_artifacts() {
// def manifests = "ls packer-artifacts/*.manifest".execute()
// println manifests.text
// def manifest_data = readFile manifest
// def manifest_json = parse_json(manifest_data)
// echo manifest_json.builds.files
}
@NonCPS // has to be NonCPS or the build breaks on the call to .each
def list_packer_tpls(list) {
list.each { item ->
echo "${item}"
}
}
pipeline {
agent any
environment {
TMPDIR = "./tmp"
HTTP_PROXY = "${http_proxy}"
HTTPS_PROXY = "${http_proxy}"
}
stages {
stage("List packer templates") {
steps {
list_packer_tpls(packer_tpl)
}
}
stage("Remove artifacts") {
steps {
cleanup_artifacts()
}
}
stage("Packer build") {
steps {
sh "mkdir ${TMPDIR} 2>/dev/null || true"
script {
for (int i = 0; i < packer_tpl.size(); ++i) {
sh "packer build ${packer_tpl[i]}.json"
}
}
}
post {
failure {
cleanup_artifacts()
}
success {
list_artifacts()
}
}
}
stage("Upload packer images") {
steps {
sh "mkdir ${packer_dir} 2>/dev/null || true"
sh "find packer-artifacts -type f -name *.raw -exec mv -f {} ${packer_dir} \\;"
}
}
}
}