jenkins pipeline流水线模板

//部署集群的证书ID
def credential = 'sample'
//集群的APIserver地址,需保证从Jenkins集群可以正常访问该地址
def apiserver = 'https://10.10.29.155:5443'


node('master'){

stage('Clone'){
echo "workdir ---------------====> ${env.WORKDIR}"
dir("${env.WORKDIR}"){
echo "1.Clone Repo"
git credentialsId: '2', branch: 'develop', url: 'http://git.piesat.cn:10003/WuhanRDC/Project/PiesatWH_PIE_Engine_AI_java.git'
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()

}


}
stage('Test'){
echo "2.Test Stage"
}
stage('bulit env'){
echo "3.开始执行打包操作......."
dir("${env.WORKDIR}/javacode_pie_image/predict-layer-manager/"){
sh "/usr/share/maven/apache-maven-3.8.5/bin/mvn clean package -DskipTests"
}
}
stage('rm'){
echo "4.rm the images of history"
dir("${env.WORKDIR}/javacode_pie_image/predict-layer-manager/"){
sh "docker rmi -f swr.cn-north-4.myhuaweicloud.com/pie-engine-ai-dev/predict-layer-manager:1.0.0"
}
}
stage('docker-Build'){
echo "5.Build Docker Image Stage"
dir("${env.WORKDIR}/javacode_pie_image/predict-layer-manager/"){
sh "docker build -t swr.cn-north-4.myhuaweicloud.com/pie-engine-ai-dev/predict-layer-manager:1.0.0 ."
}
}
stage('Push'){
echo "6.Push Docker Image Stage"
sh "docker login -u cn-north-4@JSYNBDA6S8JGMI2XY6GG -p 7b52f3f04ef308034964e3f2a8388b8a46d0399dab925de1dcda639c73878278 swr.cn-north-4.myhuaweicloud.com"
sh "docker push swr.cn-north-4.myhuaweicloud.com/pie-engine-ai-dev/predict-layer-manager:1.0.0"
}
stage('CHANGE YAML'){
echo "7.This is a deploy step to test"
dir("${env.WORKDIR}/config_yaml/"){
sh "sed -i 's/<BUILD_TAG>/1.0.0/' predict-layer-manager.yaml"
sh "cat predict-layer-manager.yaml"
}
}
stage('Deploy'){
echo "8.begin to config kubenetes"
dir("${env.WORKDIR}/config_yaml/"){
try {
sh 'kubectl delete -f predict-layer-manager.yaml'
sh 'sleep 3'
sh 'kubectl apply -f predict-layer-manager.yaml'
println "hooray, success"
} catch (e) {
println "oh no! Deployment failed! "
println e
}
}
}
}


posted @ 2022-09-21 14:01  追梦boyaaa  阅读(254)  评论(0编辑  收藏  举报