Jenkins build file
This commit is contained in:
parent
dcc0b6607b
commit
675b5a30a7
81
Jenkinsfile
vendored
Normal file
81
Jenkinsfile
vendored
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
kubernetes {
|
||||||
|
defaultContainer 'kaniko'
|
||||||
|
yaml """
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: kaniko
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: kaniko
|
||||||
|
image: gcr.io/kaniko-project/executor:v1.5.1-debug
|
||||||
|
imagePullPolicy: Always
|
||||||
|
command:
|
||||||
|
- /busybox/cat
|
||||||
|
tty: true
|
||||||
|
volumeMounts:
|
||||||
|
- name: jenkins-docker-cfg
|
||||||
|
mountPath: /kaniko/.docker
|
||||||
|
volumes:
|
||||||
|
- name: jenkins-docker-cfg
|
||||||
|
projected:
|
||||||
|
sources:
|
||||||
|
- secret:
|
||||||
|
name: docker-credentials
|
||||||
|
items:
|
||||||
|
- key: data
|
||||||
|
path: config.json
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
environment {
|
||||||
|
IMAGE_PUSH_DESTINATION="ghcr.io/ruakij/routingtabletowg"
|
||||||
|
IMAGE_TAG=""
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage("Pre-build") {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
|
||||||
|
script {
|
||||||
|
|
||||||
|
version = $(git describe --tags --long)
|
||||||
|
commitHash = $(git rev-parse HEAD)
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
def parts = version.split(/[-.]/)
|
||||||
|
for (int i = 0; i < parts.size(); i++) {
|
||||||
|
IMAGE_TAG += parts[i]
|
||||||
|
if (i < parts.size() - 1) {
|
||||||
|
IMAGE_TAG += ','
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
IMAGE_TAG = commitHash
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($GIT_BRANCH == 'main') {
|
||||||
|
IMAGE_TAG += ',latest'
|
||||||
|
} else {
|
||||||
|
IMAGE_TAG += ','$GIT_BRANCH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build with Kaniko') {
|
||||||
|
steps {
|
||||||
|
container(name: 'kaniko', shell: '/busybox/sh') {
|
||||||
|
withEnv(['PATH+EXTRA=/busybox']) {
|
||||||
|
// Use the image tag variable as part of the image name when you build and push the image with kaniko
|
||||||
|
sh '''#!/busybox/sh
|
||||||
|
/kaniko/executor --context `pwd` --destination $IMAGE_PUSH_DESTINATION --force --build-arg=IMAGE_TAG=$IMAGE_TAG
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user