-
Notifications
You must be signed in to change notification settings - Fork 54
/
Jenkinsfile
106 lines (102 loc) · 3.91 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
// vim: set filetype=groovy:
def image_local_name = "imagetagger"
def image_base_name = "ghcr.io/bit-bots/imagetagger"
pipeline {
agent {
kubernetes {
yaml """
kind: Pod
spec:
containers:
- name: kustomize
image: docker.io/nekottyo/kustomize-kubeval
tty: true
command:
- cat
- name: podman
image: quay.io/podman/stable
tty: true
securityContext:
privileged: true
command:
- cat
"""
}
}
options {
skipDefaultCheckout(true)
}
stages {
stage("Checkout SCM") {
steps {
checkout scm
}
}
stage("Check Kubernetes config validity") {
steps {
container("kustomize") {
gitStatusWrapper(
credentialsId: "github-credentials",
description: "Check Kubernetes config validity",
failureDescription: "Kubernetes config is not valid",
successDescription: "Kubernetes config is valid",
gitHubContext: "check-k8s"
) {
sh "kustomize build . > k8s.yml"
sh "kubeval k8s.yml --strict"
}
}
}
}
stage("Build Container Image") {
steps {
container("podman") {
gitStatusWrapper(
credentialsId: "github-credentials",
description: "Build the container image",
failureDescription: "Container image failed to build",
successDescription: "Container image was successfully built",
gitHubContext: "build-container-image"
) {
sh "podman build -t ${image_local_name} ."
}
}
}
}
stage("Upload Container Image") {
steps {
container("podman") {
gitStatusWrapper(
credentialsId: "github-credentials",
description: "Upload the container image",
failureDescription: "Could not upload the container image",
successDescription: "Container upload was successful or skipped",
gitHubContext: "upload-container-image"
) {
milestone(ordinal: 100)
script {
withCredentials([usernamePassword(
credentialsId: 'github-credentials',
passwordVariable: 'registry_password',
usernameVariable: 'registry_username'
)]) {
if (env.TAG_NAME != null) {
// tag events get pushed as the corresponding tag
sh "podman login ghcr.io -u $registry_username -p $registry_password"
sh "podman tag ${image_local_name} ${image_base_name}:${env.TAG_NAME}"
sh "podman push ${image_base_name}:${env.TAG_NAME}"
}
if (env.BRANCH_IS_PRIMARY == "true") {
// commit events get pushed as :dev-latest
sh "podman login ghcr.io -u $registry_username -p $registry_password"
sh "podman tag ${image_local_name} ${image_base_name}:dev-latest"
sh "podman push ${image_base_name}:dev-latest"
}
}
}
}
}
}
}
}
}