-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
109 lines (108 loc) · 3.07 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
library 'pipeline-utils@master'
pipeline {
agent {
kubernetes {
yaml '''
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: jnlp
workingDir: /home/jenkins/agent
- name: kaniko
workingDir: /home/jenkins/agent
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
resources:
requests:
cpu: "500m"
memory: "1Gi"
ephemeral-storage: "4Gi"
limits:
cpu: "1000m"
memory: "2Gi"
ephemeral-storage: "4Gi"
command:
- /busybox/cat
tty: true
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /kaniko/.docker
- name: crane
workingDir: /tmp/jenkins
image: gcr.io/go-containerregistry/crane:debug
imagePullPolicy: Always
command:
- /busybox/cat
tty: true
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: rencibuild-imagepull-secret
items:
- key: .dockerconfigjson
path: config.json
'''
}
}
environment {
PATH = "/busybox:/kaniko:/ko-app/:$PATH"
DOCKERHUB_CREDS = credentials("${env.REGISTRY_CREDS_ID_STR}")
REGISTRY = "${env.DOCKER_REGISTRY}"
REG_OWNER="helxplatform"
REG_APP="heal-sparc-converter"
COMMIT_HASH="${sh(script:"git rev-parse --short HEAD", returnStdout: true).trim()}"
VERSION_FILE="./_version.py"
VERSION="${sh(script:'awk \'{ print $3 }\' ./_version.py | xargs', returnStdout: true).trim()}"
IMAGE_NAME="${REG_OWNER}/${REG_APP}"
TAG1="$BRANCH_NAME"
TAG2="$COMMIT_HASH"
TAG3="$VERSION"
TAG4="latest"
}
stages {
stage('Test') {
steps {
sh '''
echo "Stage test"
'''
}
}
stage('Build') {
steps {
script {
container(name: 'kaniko', shell: '/busybox/sh') {
kaniko.build("./Dockerfile", ["$IMAGE_NAME:$TAG1", "$IMAGE_NAME:$TAG2", "$IMAGE_NAME:$TAG3", "$IMAGE_NAME:$TAG4"])
}
}
}
post {
always {
archiveArtifacts artifacts: 'image.tar', onlyIfSuccessful: true
}
}
}
stage('Publish') {
steps {
script {
container(name: 'crane', shell: '/busybox/sh') {
def imageTagsToPushAlways = ["$IMAGE_NAME:$TAG1", "$IMAGE_NAME:$TAG2"]
def imageTagsToPushForDevelopBranch = ["$IMAGE_NAME:$TAG3"]
def imageTagsToPushForMasterBranch = ["$IMAGE_NAME:$TAG4"]
image.publish(imageTagsToPushAlways, imageTagsToPushForDevelopBranch, imageTagsToPushForMasterBranch)
}
}
}
post {
cleanup {
sh '''
echo "Remove archived artifacts."
'''
}
}
}
}
}