SpringBoot项目发版Pipeline
程序员文章站
2022-05-08 17:37:45
...
def ServiceName = "demo"
def ProjectDir = "demo"
def DockerfileDir = "project/demo"
def gitCommit
def gitBranch
def shortGitCommit
node {
def DOCKER_HUB_ADDR='registry.test.inside'
stage('Git Clone and setup') {
dir("docker") {
git credentialsId: 'Testgitlab', url: 'http://git.test.work/ops/cicd.git', branch: 'test'
}
dir("source") {
def myRepo = checkout([$class: 'GitSCM',
branches: [[name: '*/test']],
userRemoteConfigs: [[credentialsId: '70cxxx-2xce-4xef-94xf-a5axxxaa198b', url: '[email protected]:project/demo.git']]
])
gitCommit = myRepo.GIT_COMMIT
gitBranch = myRepo.GIT_BRANCH
shortGitCommit = "${gitCommit[0..5]}"
}
}
stage('Build') {
try {
sh """
mvn -s /etc/maven/settings.xml -f source/pom.xml clean -X package -Ptest -Dmaven.test.skip=true
"""
}
catch (exc) {
println "Failed to test - ${currentBuild.fullDisplayName}"
throw(exc)
}
}
stage('Sonarqube') {
sh """
mvn -s /etc/maven/settings.xml -f source/pom.xml sonar:sonar -Dsonar.organization="test" -Dsonar.projectKey=${ServiceName} \
-Dsonar.projectName=${ServiceName} -Dsonar.host.url=http://sonar.test.work:9000 -Dsonar.login=xxxxxe2c63f
"""
}
stage('Publish Docker') {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'dockerhub',
passwordVariable: 'DOCKER_HUB_PASSWORD',
usernameVariable: 'DOCKER_HUB_USER']]) {
sh """
docker login ${DOCKER_HUB_ADDR} -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD}
docker build \
--build-arg app=${ServiceName} \
-t ${DOCKER_HUB_ADDR}/project/${ServiceName}:${shortGitCommit} \
-f docker/${DockerfileDir}/Dockerfile \
source/${ProjectDir}/target
docker push ${DOCKER_HUB_ADDR}/project/${ServiceName}:${shortGitCommit}
"""
}
}
stage('Deploy to test') {
sh """
helm init \
--client-only \
--stable-repo-url \
http://10.20.10.106:8080
helm repo update
if ! helm ls --output=yaml |grep "Chart: ${ServiceName}-0";then
helm install \
--namespace=default \
--name=${ServiceName} \
--set image.tag=${shortGitCommit} \
--description "Install -> ${shortGitCommit}" \
stable/${ServiceName}
fi
"""
def NodePort=sh([script: "kubectl get svc -n default -l app.kubernetes.io/name=${ServiceName} -o jsonpath='{.items[0].spec.ports..nodePort}'",returnStdout:true]).trim()
sh """
helm upgrade ${ServiceName} \
--set image.repository=${DOCKER_HUB_ADDR}/project/${ServiceName},image.tag=${shortGitCommit},port.containerPort=${NodePort} \
--description "Upgrade -> ${shortGitCommit}" \
stable/${ServiceName}
"""
}
}
推荐阅读
-
javascript - web项目发版如何解决静态资源JS CSS 缓存问题
-
springboot2.0和springcloud Finchley版项目搭建(包含eureka,gateWay,Freign,Hystrix)
-
解决在vue项目中,发版之后,背景图片报错,路径不对的问题
-
k8s + docker + Jenkins使用Pipeline部署SpringBoot项目时Jenkins错误集锦
-
IDEA新建一个简单的springboot项目(选择maven版)
-
IDEA新建一个简单的springboot项目(选择maven版)
-
springboot项目结合filter,jdk代理实现敏感词过滤(简单版)
-
解决在vue项目中,发版之后,背景图片报错,路径不对的问题
-
javascript - web项目发版如何解决静态资源JS CSS 缓存问题
-
k8s + docker + Jenkins使用Pipeline部署SpringBoot项目时Jenkins错误集锦