forked from FortnoxAB/kube-annotations-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
79 lines (69 loc) · 1.86 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
#!/usr/bin/env groovy
// vim: ft=Jenkinsfile
library 'whatsout'
node('go1.21') {
container('run'){
def newTag = ''
def tag = ''
def gitTag = ''
try {
stage('Checkout'){
checkout scm
gitTag = sh(script: 'git tag -l --contains HEAD', returnStdout: true).trim()
}
stage('Fetch dependencies'){
// using ID because: https://issues.jenkins-ci.org/browse/JENKINS-32101
sshagent(credentials: ['github-key']) {
//sh('go get -d -v -t ./...')
sh('go mod download')
}
}
stage('Run test'){
sh('make test')
}
if(gitTag != ''){
tag = gitTag
}else if (env.BRANCH_NAME == 'master'){
stage('create tag') {
CURR_TAG = sh(
script: "git for-each-ref --count=1 --sort=-v:refname --format '%(tag)' refs/tags/v*",
returnStdout: true
).trim()
echo "current tag: "+CURR_TAG
if(CURR_TAG == ''){
CURR_TAG = 'v0'
}
PARTS = CURR_TAG.replaceFirst('v','').split('\\.')
PARTS[PARTS.length-1] = (PARTS[PARTS.length-1] as int)+1
newTag = 'v'+PARTS.join(".")
sshagent(credentials: ['github-key']) {
sh('git config user.email "[email protected]"')
sh('git config user.name "jenkins"')
sh("git tag -a ${newTag} -m ${newTag}")
sh("git push origin ${newTag}")
}
tag = newTag
}
createRelease(CURR_TAG, newTag, 'kube-annotations-exporter', 'kube-annotations-exporter')
}
if( tag != ''){
stage('Build the application'){
echo "Building with docker tag ${tag}"
docker.withRegistry("https://quay.io", 'docker-registry') {
sh("VERSION=${tag} make push")
}
}
}
currentBuild.result = 'SUCCESS'
} catch(err) {
currentBuild.result = 'FAILED'
if (newTag != '') {
sshagent(credentials: ['github-key']) {
sh("git tag -d ${tag}")
sh("git push --delete origin ${tag}")
}
}
throw err
}
}
}