-
Notifications
You must be signed in to change notification settings - Fork 29
/
release.Jenkinsfile
98 lines (91 loc) · 2.89 KB
/
release.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
@Library('whiteblock-dev')
import github.Release
import helm.Chart
String imageName = 'genesis'
String registry = 'gcr.io/infra-dev-249211'
String chartDir = 'chart/genesis'
String gitTagCredentialsId = 'github-repo-pac'
String repo = 'genesis'
// see: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
def semverRegex = ~/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
pipeline {
agent any
environment {
REV_SHORT = sh(script: "git rev-parse HEAD", returnStdout: true).trim()
}
parameters {
string(name: "tag_name", description: "(REQUIRED) The name of the tag.")
string(
name: "target_commitish",
defaultValue: "master",
description: "Specifies the commitish value that determines where the Git tag is created from."
)
text(name: "body", defaultValue: '', description: "Description of the release")
}
stages {
stage('validate tag') {
steps {
script {
// not `def release` so that the variable can be used in github release stage
release = new github.Release(
tag_name: params.tag_name,
body: params.body,
target_commitish: params.target_commitish,
repo: repo
)
withCredentials([
usernameColonPassword(credentialsId: gitTagCredentialsId, variable: 'USERPASS')
]) {
validateTag(release, env.USERPASS)
}
}
}
}
stage('publish artifacts') {
steps {
script {
source = new container.Image(
registry: registry,
name: imageName,
/*
NOTE: Ignores target_commitish value and gets the latest build
from master branch no matter what
*/
tag: "${env.REV_SHORT}"
)
target = new container.Image(
registry: registry,
name: imageName,
tag: "${params.tag_name}"
)
tagContainerImage(source, target)
// just here for convenience when
// manually installing chart from source
target = new container.Image(
registry: registry,
name: imageName,
tag: "latest"
)
tagContainerImage(source, target)
chart = new helm.Chart(
directory: chartDir,
version: params.tag_name
)
publishHelmChart(chart)
}
}
}
stage('github release') {
steps {
script {
withCredentials([
usernameColonPassword(credentialsId: gitTagCredentialsId, variable: 'USERPASS')
]) {
String text = createRelease(release, env.USERPASS)
println text
}
}
}
}
}
}