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.