协jenkins-dat-task-flow
pipeline { // 选择标签为maven的模板 agent { node { label "maven" } } options { buildDiscarder(logRotator(numToKeepStr: '10')) } parameters { gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH' } environment { AppName = "${AppName}" GitRepo = "${GitRepo}" GitBranch = "${GitBranch}" HarborUrl = "${HarborUrl}" Image = "${Image}" JAVA_OPTS = "${JAVA_OPTS}" } stages{ stage('代码拉取') { steps { script { checkout scmGit(branches: [[name: '${BRANCH}']], extensions: [], userRemoteConfigs: [[credentialsId: 'rd', url: 'https://codeup.aliyun.com/glr/rd-manage/rd-manage-web/backend-cloud.git']]) env.BUILD_TAG = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() env.APP_NAME = sh(returnStdout: true, script: "git config -l|git config -l|grep remote.origin.url|awk -F/ '{print \$NF}'|cut -d. -f1").trim() } } } stage('代码编译') { steps { script { sh " mvn -B clean package -Dmaven.test.skip=true -Dautoconfig.skip" } } } stage('镜像构建、上传') { steps { script { withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'dockerHubPassword',usernameVariable: 'dockerHubUser')]) { sh "docker login -u ${dockerHubUser} -p ${dockerHubPassword} harbor.glroad.com:8800" sh "cd /home/jenkins/agent/workspace/rd-manage-java-dat-task-flow-pre/ruoyi-modules/dat-task-flow && docker build -t harbor.glroad.com:8800/rd-manage-web/dat-task-flow:${BUILD_TAG}-${BUILD_ID} ." sh "docker push harbor.glroad.com:8800/rd-manage-web/dat-task-flow:${BUILD_TAG}-${BUILD_ID}" } } } } stage('部署&更新') { steps { script { sh "echo 900000" sh "kubectl set image deployment/rd-manage-java-dat-task-flow rd-manage-java-dat-task-flow=harbor.glroad.com:8800/rd-manage-web/dat-task-flow:${BUILD_TAG}-${BUILD_ID} -n rd" } } } } }