-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
113 lines (99 loc) · 3.83 KB
/
Jenkinsfile
File metadata and controls
113 lines (99 loc) · 3.83 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!groovy
@Library('github.com/cloudogu/ces-build-lib@bc16ce2e')
import com.cloudogu.ces.cesbuildlib.*
pipeline {
agent {
docker {
image 'ghcr.io/cloudogu/helm:3'
args '--entrypoint=""'
}
}
environment {
HELM_REPO_URL = 'ghcr.io/cloudogu'
CHART_VERSION = sh(script: "grep '^version:' Chart.yaml | awk '{print \$2}'", returnStdout: true).trim()
CHART_NAME = sh(script: "grep '^name:' Chart.yaml | awk '{print \$2}'", returnStdout: true).trim()
}
stages {
stage('Checkout') {
steps {
checkout scm
script {
// Jenkins seems to do a sparse checkout only, but we want to check tags as well
sh "git fetch --tags --force"
}
}
}
stage('Validate Chart') {
steps {
sh '''
helm version
helm lint .
'''
}
}
stage('Run Unit Tests') {
steps {
sh '''
helm plugin install https://github.com/helm-unittest/helm-unittest > /dev/null
helm unittest .
'''
}
}
stage('Package Chart') {
steps {
sh '''
helm package .
'''
archiveArtifacts artifacts: "*.tgz", fingerprint: true
}
}
stage('Push to Helm Repository') {
when {
branch 'main'
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'cesmarvin-ghcr', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
sh '''
# Seems difficult with jenkins
# git tag $CHART_VERSION
# git push --tags
CURRENT_TAG=$(git tag --points-at HEAD)
# Check if both conditions are true
if [[ -n "$CURRENT_TAG" ]] && [[ "$CURRENT_TAG" == "$CHART_VERSION" ]]; then
helm registry login ${HELM_REPO_URL} -u $USER -p $PASSWORD
if helm pull oci://${HELM_REPO_URL}/${CHART_NAME} --version $CHART_VERSION; then
echo "Error: Chart version already exists in repository"
exit 1
fi
helm push $(ls *.tgz) oci://${HELM_REPO_URL}
echo "$CHART_VERSION" > pushedVersion.txt
else
echo "Not pushing :"
if [[ -z "$CURRENT_TAG" ]]; then
echo "- Current HEAD has no tag"
else
echo "- Current HEAD tag: $CURRENT_TAG"
echo "- Chart version: $CHART_VERSION"
echo "Tag and chart version missmatch!"
exit 1
fi
fi
'''
if (fileExists('pushedVersion.txt')) {
currentBuild.description = "$HELM_REPO_URL/$CHART_NAME:${readFile 'pushedVersion.txt'}"
sh 'rm pushedVersion.txt'
}
}
}
}
}
}
post {
always {
script {
mailIfStatusChanged(new Git(this).commitAuthorEmail)
}
}
}
}