diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a2d13a0 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,77 @@ +def IMAGE_TAG = "" +pipeline { + agent { + kubernetes { + 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" + } + stages { + stage("Pre-build") { + steps { + checkout scm + + script{ + def version = sh (returnStdout: true, script: "git describe --tags --long --always").trim() + IMAGE_TAG = "--destination $IMAGE_PUSH_DESTINATION:$version " + echo "Version: $version" + + def parts = version.split('.') + if(parts.size() > 0){ + for (int i = 0; i < parts.size(); i++) { + def versionTag = parts[0..i].join(".") + IMAGE_TAG += "--destination $IMAGE_PUSH_DESTINATION:$versionTag " + } + } + + if (GIT_BRANCH == "main") { + IMAGE_TAG += "--destination $IMAGE_PUSH_DESTINATION:latest " + } else { + IMAGE_TAG += "--destination $IMAGE_PUSH_DESTINATION:$GIT_BRANCH " + } + echo "Image-Tags: $IMAGE_TAG" + } + } + } + + 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` --force $IMAGE_TAG + ''' + } + } + } + } + } +}