-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
95 lines (94 loc) · 2.81 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
library 'pipeline-utils@master'
pipeline {
agent {
kubernetes {
label 'kaniko-build-agent'
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: "512m"
memory: "1024Mi"
ephemeral-storage: "2Gi"
limits:
cpu: "1024m"
memory: "2048Mi"
ephemeral-storage: "2Gi"
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.CONTAINERS_REGISTRY_CREDS_ID_STR}")
GITHUB_CREDS = credentials("${env.GITHUB_CREDS_ID_STR}")
REGISTRY = "${env.REGISTRY}"
REG_OWNER="helxplatform"
REPO_NAME="dug"
COMMIT_HASH="${sh(script:"git rev-parse --short HEAD", returnStdout: true).trim()}"
IMAGE_NAME="${REGISTRY}/${REG_OWNER}/${REPO_NAME}"
}
stages {
stage('Build') {
steps {
script {
container(name: 'go', shell: '/bin/bash') {
if (BRANCH_NAME.equals("master")) {
CCV = go.ccv()
}
}
container(name: 'kaniko', shell: '/busybox/sh') {
def tagsToPush = ["$IMAGE_NAME:$BRANCH_NAME", "$IMAGE_NAME:$COMMIT_HASH"]
if (CCV != null && !CCV.trim().isEmpty() && BRANCH_NAME.equals("master")) {
tagsToPush.add("$IMAGE_NAME:$CCV")
tagsToPush.add("$IMAGE_NAME:latest")
} else if (BRANCH_NAME.equals("develop")) {
def now = new Date()
def currTimestamp = now.format("yyyy-MM-dd'T'HH.mm'Z'", TimeZone.getTimeZone('UTC'))
tagsToPush.add("$IMAGE_NAME:$currTimestamp")
}
kaniko.buildAndPush("./Dockerfile", tagsToPush)
}
}
}
}
stage('Test') {
steps {
sh '''
echo "Test stage"
'''
}
}
}
}