Hi all,
I’m Jenkins newbie.
My Jenkins installed Kubernetes plugin.
The pipeline below works fine
pipeline {
agent {
kubernetes {
yamlFile 'Jenkins-agent-pod.yaml' // this file existed in my repo
}
}
environment {
DOCKERFILE_PATH = 'Dockerfile' // this file existed in my repo
DOCKER_IMAGE_NAME = 'dockerhub-repo/app:tag'
}
stages {
stage('Build and Push Docker Image with Kaniko') {
steps {
container(name: 'kaniko', shell: '/busybox/sh') {
withCredentials([file(credentialsId: 'dockerhub', variable: 'DOCKER_CONFIG_JSON')]) {
withEnv(['PATH+EXTRA=/busybox']) {
sh '''#!/busybox/sh
cp $DOCKER_CONFIG_JSON /kaniko/.docker/config.json
/kaniko/executor --context `pwd` --dockerfile $DOCKERFILE_PATH --destination $DOCKER_IMAGE_NAME
'''
}
}
}
}
}
}
}
Now I want to write stage(‘Build and Push Docker Image with Kaniko’) as shared library method
What should I do ?
I create a new repo as jack-shared-library , with vars/buildImage2.groovy
How should I write buildImage2.groovy ?
How should I write pipeline to use buildImage2 ?
Please give me some advice, thank you very much.
Thank you for the content Jack. I’m Jenkins newbie more then you. First of all I have no experience groovy and SharedLibraries but I am at the phase of learning.
I would like to create “dynamic PVC” for multiple K8s pods and I would like to use Shared Library for this. This dynamic PVC should be “sharable between Pods” And when pipeline finish its job at the end this “dynamic PVC” shoul be destroyed automaticaly. I mean I want to automate this process for every pipeline using with shared libraries.
Also I am using jenkins in Kubernetes, and kubenetes pods as jenkins agents ( with the jenkins-kubernetes plugin.
Thanks in advance for anybody in the community who gives any idea