forked from coreos/fedora-coreos-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.stream.metadata.generator
68 lines (60 loc) · 2.92 KB
/
Jenkinsfile.stream.metadata.generator
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
def utils, streams
node {
checkout scm
utils = load("utils.groovy")
streams = load("streams.groovy")
pod = readFile(file: "manifests/pod.yaml")
}
properties([
pipelineTriggers([]),
parameters([
choice(name: 'STREAM',
// list devel first so that it's the default choice
choices: (streams.production),
description: 'Fedora CoreOS stream metadata'),
string(name: 'VERSION',
description: 'Fedora CoreOS version getting released',
defaultValue: '',
trim: true)
])
])
currentBuild.description = "[${params.STREAM}] - ${params.VERSION}"
pod = pod.replace("COREOS_ASSEMBLER_IMAGE", "coreos-assembler:master")
// shouldn't need more than 256Mi for this job
pod = pod.replace("COREOS_ASSEMBLER_MEMORY_REQUEST", "256Mi")
// use a unique label to force Kubernetes to provision a separate pod per run
def pod_label = "cosa-${UUID.randomUUID().toString()}"
podTemplate(cloud: 'openshift', label: pod_label, yaml: pod) {
node(pod_label) { container('coreos-assembler') {
stage('Stream Metadata' ) {
def gopath = "${env.WORKSPACE}" + "/go/"
def gocache = "${env.WORKSPACE}" + "/gocache/"
def coreosbot_token = utils.shwrap_capture("cat /.github/token")
def bot_name = "CoreOS Bot"
def bot_email = "[email protected]"
def bot_username = "coreosbot"
def pr_branch = "bot-pr-" + "${env.BUILD_ID}"
utils.shwrap("""
mkdir go gocache
export GOPATH=$gopath
export GOCACHE=$gocache
go get -u github.com/coreos/fedora-coreos-stream-generator
""")
utils.shwrap_quiet("""
git clone https://${bot_username}:${coreosbot_token}@github.com/coreos/fedora-coreos-streams ${env.WORKSPACE}/fedora-coreos-streams
""")
// Generate stream metadata for the stream and create Pull Request
utils.shwrap("""
cd ${env.WORKSPACE}/fedora-coreos-streams/ && git checkout -b ${pr_branch}
$gopath/bin/fedora-coreos-stream-generator -releases=https://builds.coreos.fedoraproject.org/prod/streams/${params.STREAM}/releases.json -output-file=streams/${params.STREAM}.json --pretty-print
git add streams/${params.STREAM}.json && git -c "user.name=${bot_name}" -c "user.email=${bot_email}" commit -m "Stream metadata for ${params.STREAM} release ${params.VERSION}"
git push origin ${pr_branch}
""")
// Creating the Pull Request
utils.shwrap_quiet("""
cd ${env.WORKSPACE}/fedora-coreos-streams/
curl -H "Authorization: token ${coreosbot_token}" -X POST -d '{"title": "Stream metadata for ${params.STREAM} release ${params.VERSION}","head": "${pr_branch}","base": "master"}' https://api.github.com/repos/coreos/fedora-coreos-streams/pulls
""")
}
}}
}