-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
85 lines (77 loc) · 3 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
pipeline {
agent { label "chart-testing-agent" }
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages {
stage("Lint") {
steps {
container("chart-testing") {
sh "ct lint"
}
}
}
stage("Install & Test") {
steps {
container("chart-testing") {
sh "ct install --upgrade"
}
}
}
stage("Package Charts") {
steps {
script {
container("chart-testing") {
sh "helm package --dependency-update helm-charts/charts/*"
}
}
}
}
stage("Push Charts to Chart Repo") {
steps {
script {
container("chart-testing") {
// Handle master -> main branch renaming
def baseBranch = "main"
if (env.GITHUB_PAGES_BASE_BRANCH) {
baseBranch = env.GITHUB_PAGES_BASE_BRANCH
}
// Clone GitHub Pages repository to a folder called "chart-repo"
sh "git clone ${env.GITHUB_PAGES_REPO_URL} chart-repo"
// Determine if these charts should be pushed to "stable" or "staging" based on the branch
def repoType
if (env.BRANCH_NAME == baseBranch) {
repoType = "stable"
} else {
repoType = "staging"
}
// Create the corresponding "stable" or "staging" folder if it does not exist
def files = sh(script: "ls chart-repo", returnStdout: true)
if (!files.contains(repoType)) {
sh "mkdir chart-repo/${repoType}"
}
// Move packaged charts to the corresponding "stable" or "staging" folder
sh "mv *.tgz chart-repo/${repoType}"
// Generate the updated index.yaml
sh "helm repo index chart-repo/${repoType}"
// Update git config details
sh "git config --global user.email '[email protected]'"
sh "git config --global user.name 'chartrepo-robot'"
dir("chart-repo") {
// Add and commit the changes
sh "git add --all"
sh "git commit -m 'pushing charts from branch ${env.BRANCH_NAME}'"
withCredentials([usernameColonPassword(credentialsId: 'github-auth', variable: 'USERPASS')]) {
script {
// Inject GitHub auth and push to the repo where charts are being served
def authRepo = env.GITHUB_PAGES_REPO_URL.replace("://", "://${USERPASS}@")
sh "git push ${authRepo} ${baseBranch}"
}
}
}
}
}
}
}
}
}