Example Pipeline Script for Image Build, Pushing, and Deployment
Example pipeline script:
node('slave'){
stage('Clone') {
echo "1.Clone Stage"
git url: "https://github.com/lookforstar/jenkins-demo.git"
script {
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}
}
stage('Test') {
echo "2.Test Stage"
}
stage('Build') {
echo "3.Build Docker Image Stage"
sh "docker build -t swr.cn-east-3.myhuaweicloud.com/batch/jenkins-demo:${build_tag} ."
}
stage('Push') {
echo "4.Push Docker Image Stage"
sh "docker login -u cn-east-3@82EFQWQMJWSDOYS9BQNM -p 71b0cceac30a10b99a960360b2e1deb04ec2f1bb00e88bc5eb69f3e9fd6a6d08 swr.cn-east-3.myhuaweicloud.com"
sh "docker push swr.cn-east-3.myhuaweicloud.com/batch/jenkins-demo:${build_tag}"
}
stage('Deploy') {
echo "5. Deploy Stage"
echo "This is a deploy step to test"
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' *.yaml"
sh "cat *.yaml"
echo "begin to config kubenetes"
try {
kubernetesDeploy(
kubeconfigId: "mogujie-spark-zxx",
configs: "k8s.yaml")
println "hooray, success"
} catch (e) {
println "oh no! Deployment failed! "
println e
}
}
}
Last Article: Interconnecting Jenkins with CCE Clusters
Next Article: Interconnecting Jenkins with RBAC of Kubernetes Clusters (Example)
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.