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'
}
}
}
}
}
jenkins pipeline记录
于 2022-02-08 09:47:28 首次发布