-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
80 lines (78 loc) · 3.27 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
properties([disableConcurrentBuilds(), buildDiscarder(logRotator(artifactDaysToKeepStr: '5', artifactNumToKeepStr: '5', daysToKeepStr: '5', numToKeepStr: '5'))])
@Library('pipeline-library')
import dk.stiil.pipeline.Constants
podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command:
- sleep
args:
- 99d
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker
restartPolicy: Never
volumes:
- name: kaniko-secret
secret:
secretName: dockerhub-dockercred
items:
- key: .dockerconfigjson
path: config.json
''') {
node(POD_LABEL) {
TreeMap scmData
String gitCommitMessage
stage('checkout SCM') {
scmData = checkout scm
gitCommitMessage = sh(returnStdout: true, script: "git log --format=%B -n 1 ${scmData.GIT_COMMIT}").trim()
arch = sh(returnStdout: true, script: '''
case $(uname -m) in
armv5*) echo "armv5";;
armv6*) echo "armv6";;
armv7*) echo "arm";;
aarch64) echo "arm64";;
x86) echo "386";;
x86_64) echo "amd64";;
i686) echo "386";;
i386) echo "386";;
esac''').trim()
gitMap = scmGetOrgRepo scmData.GIT_URL
githubWebhookManager gitMap: gitMap, webhookTokenId: 'jenkins-webhook-repo-cleanup'
// Some comment
}
if ( !gitCommitMessage.startsWith("renovate/") || ! gitCommitMessage.startsWith("WIP") ) {
stage('Build Docker Image') {
container('kaniko') {
def properties = readProperties file: 'package.env'
withEnv(["GIT_COMMIT=${scmData.GIT_COMMIT}", "PACKAGE_NAME=${properties.PACKAGE_NAME}", "PACKAGE_DESTINATION=${properties.PACKAGE_DESTINATION}", "PACKAGE_CONTAINER_SOURCE=${properties.PACKAGE_CONTAINER_SOURCE}", "GIT_BRANCH=${BRANCH_NAME}", "ARCH=${arch}"]) {
if (isMainBranch()){
sh '''
/kaniko/executor --force --context `pwd` --log-format text --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME-$ARCH --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:latest --label org.opencontainers.image.description="Build based on $PACKAGE_CONTAINER_SOURCE/commit/$GIT_COMMIT" --label org.opencontainers.image.revision=$GIT_COMMIT --label org.opencontainers.image.version=$GIT_BRANCH
'''
} else {
sh '''
/kaniko/executor --force --context `pwd` --log-format text --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME-$ARCH --label org.opencontainers.image.description="Build based on $PACKAGE_CONTAINER_SOURCE/commit/$GIT_COMMIT" --label org.opencontainers.image.revision=$GIT_COMMIT --label org.opencontainers.image.version=$GIT_BRANCH
'''
}
}
}
}
}
if (env.CHANGE_ID) {
if (pullRequest.createdBy.equals("renovate[bot]")){
if (pullRequest.mergeable) {
stage('Approve and Merge PR') {
pullRequest.merge(commitTitle: pullRequest.title, commitMessage: pullRequest.body, mergeMethod: 'squash')
}
}
} else {
echo "'PR Created by \""+ pullRequest.createdBy + "\""
}
}
}
}