Create a Jenkins job using the below scripts in the Jenkins, we can modify the scripts as per our requirement.
For this job, we are using a pod-template with a kaniko executor container to build a docker image and a supporting maven container for the git checkout to the Kaniko executor.
For this job, we are using a pod-template with a kaniko executor container to build a docker image and a supporting maven container for the git checkout to the Kaniko executor.
pipeline { agent { kubernetes { yaml ''' apiVersion: v1 kind: Pod spec: containers: - name: maven image: maven:3.8.1-jdk-8 command: - sleep args: - 99d - name: kaniko image: gcr.io/kaniko-project/executor:debug command: - sleep args: - 9999999 volumeMounts: - name: kaniko-secret mountPath: /kaniko/.docker restartPolicy: Never volumes: - name: kaniko-secret secret: secretName: saas-credentials items: - key: .dockerconfigjson path: config.json ''' } } stages { stage ('Clone') { steps {container('maven') { git url: 'https://github.com/scriptcamp/kubernetes-kaniko.git', branch: 'main' } } } stage ('Exec Kaniko') { steps { container('kaniko') { sh ''' cat /kaniko/.docker/config.json /kaniko/executor --context `pwd` --destination test-docker.jfrog.io/hello-kaniko --image-name-with-digest-file=image-file ''' } } } stage ('Run create Docker build') { steps { rtCreateDockerBuild ( serverId: 'SERVER_ID', sourceRepo: 'docker', kanikoImageFile: "image-file" ) } } stage ('Publish build info') { steps { rtPublishBuildInfo ( serverId: 'SERVER_ID' ) } } } }