jenkins pipeline记录

此篇博客介绍了使用Maven进行项目构建,并通过并行阶段打包Docker镜像,包括登录、打标签和推送操作,最后部署到Kubernetes的详细流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def riqi=''
def basedir='biz-module-storage/biz-module-storage-start'
import java.text.SimpleDateFormat
pipeline {
  agent {
    node {
      label 'maven'
    }
  }
  #环境变量
  environment {
      DATETAG=""
      DEPLOY_ENV_SELECT="test"
      DEPLOY_ENV='dev'
      BRANCH_ENV='dev'
      PROJECT='p-lms-istio'
      VERSION='test'
      DOCKER_NAME='biz-module-storage'
      DOCKER_HUB='hub.fqi.com'
      DEPLOYMENT='biz-module-storage'
      CONTAINER='biz-module-storage'
      MODULE = 'biz-module-storage'
  }
  
  stages {
    stage('获取代码') {
      steps {
        git(credentialsId: 'gitlab', url: 'ssh://git@192.168.3.4:7003/root/p-lms-back.git', branch: 'istio', changelog: true, poll: false)
      }
    }
    stage('Maven 构建'){
      steps {
          container ('maven') {
            /*dir('jeecg-boot-starter/jeecg-boot-starter-cloud'){
               sh 'mvn -f pom.xml -Dmaven.test.skip=true -U -P test clean install'
            }
            dir('biz-module-base'){
               sh 'mvn -f pom.xml -Dmaven.test.skip=true -U -P test clean install'
            }*/
            sh 'mvn -f pom.xml -Dmaven.test.skip=true -U -P test clean install'
          }
      }
    }
        stage('并行检查') {
      parallel {
        stage('打包Docker'){
          steps {
            container ('maven') {
              echo "start build image"
                // build镜像
              dir(basedir) { //切换文件夹 执行如下命令
                sh 'docker build --build-arg DEPLOY_ENV_SELECT=$DEPLOY_ENV_SELECT -t $PROJECT/$DOCKER_NAME-$DEPLOY_ENV:$BUILD_NUMBER .'
                // 登录镜像仓库
                sh 'docker login -u admin -p admin@123 $DOCKER_HUB'
                sh 'docker tag $PROJECT/$DOCKER_NAME-$DEPLOY_ENV:$BUILD_NUMBER $DOCKER_HUB/$PROJECT/$DOCKER_NAME-$DEPLOY_ENV:$BUILD_NUMBER'
                // 推送镜像到镜像仓库
                sh 'docker push $DOCKER_HUB/$PROJECT/$DOCKER_NAME-$DEPLOY_ENV:$BUILD_NUMBER'
              }
            }
          }
        }
        
        stage('sonarqube analysis') {
          steps {
            container('maven') {
              withCredentials([string(credentialsId: "sonar", variable: 'SONAR_TOKEN')]) {
                withSonarQubeEnv('sonar') {
                  dir('biz-module-storage') {
                    sh 'mvn sonar:sonar -Dsonar.projectKey=biz-module-storage -Dsonar.host.url=http://192.168.3.66:10893 -Dsonar.login=2fc7d3229a146862c824bbbb5f959761eb58b872'
                  }
                }
              }
              timeout(time: 1, unit: 'HOURS') {
                waitForQualityGate false
              }
            }
          }
        }
      }
    }
    stage('发布kubernetes') {
      agent {
        node {
          label 'base'
        }
      }
      steps {
        container('base') {
          sh 'kubectl set image deployment/$MODULE-v1 $MODULE=$DOCKER_HUB/$PROJECT/$DOCKER_NAME-$DEPLOY_ENV:$BUILD_NUMBER -n p-lms-mesh'
        }
      }
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值