1 Star 0 Fork 17

luzhijun/sprint-boot-demo

forked from cuiliang/spring-boot-demo 
加入 Gitee
與超過 1200 萬 開發者一起發現、參與優秀開源項目,私有倉庫也完全免費 :)
免費加入
克隆/下載
Jenkinsfile-docker.groovy 4.14 KB
一鍵複製 編輯 原始數據 按行查看 歷史
cuiliang 提交於 2024-05-11 10:10 . 更新k8s部署pipeline
pipeline {
agent any
environment {
// 全局变量
HARBOR_CRED = "harbor-cuiliang-password"
IMAGE_NAME = ""
IMAGE_APP = "demo"
}
stages {
stage('拉取代码') {
environment {
// gitlab仓库信息
GITLAB_CRED = "gitlab-cuiliang-password"
GITLAB_URL = "http://192.168.10.72/develop/sprint-boot-demo.git"
}
steps {
echo '开始拉取代码'
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: "${GITLAB_CRED}", url: "${GITLAB_URL}"]])
echo '拉取代码完成'
}
}
stage('打包编译') {
steps {
echo '开始打包编译'
sh 'mvn clean package'
echo '打包编译完成'
}
}
stage('代码审查') {
environment {
// SonarQube信息
SONARQUBE_SCANNER = "SonarQubeScanner"
SONARQUBE_SERVER = "SonarQubeServer"
}
steps{
echo '开始代码审查'
script {
def scannerHome = tool "${SONARQUBE_SCANNER}"
withSonarQubeEnv("${SONARQUBE_SERVER}") {
sh "${scannerHome}/bin/sonar-scanner"
}
}
echo '代码审查完成'
}
}
stage('构建镜像') {
environment {
// harbor仓库信息
HARBOR_URL = "harbor.local.com"
HARBOR_PROJECT = "spring_boot_demo"
// 镜像名称
IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
}
steps {
echo '开始构建镜像'
script {
IMAGE_NAME = "${HARBOR_URL}/${HARBOR_PROJECT}/${IMAGE_APP}:${IMAGE_TAG}"
docker.build "${IMAGE_NAME}"
}
echo '构建镜像完成'
echo '开始推送镜像'
script {
docker.withRegistry("https://${HARBOR_URL}", "${HARBOR_CRED}") {
docker.image("${IMAGE_NAME}").push()
}
}
echo '推送镜像完成'
echo '开始删除镜像'
script {
sh "docker rmi -f ${IMAGE_NAME}"
}
echo '删除镜像完成'
}
}
stage('项目部署') {
environment {
// 目标主机信息
HOST_NAME = "springboot1"
}
steps {
echo '开始部署项目'
// 获取harbor账号密码
withCredentials([usernamePassword(credentialsId: "${HARBOR_CRED}", passwordVariable: 'HARBOR_PASSWORD', usernameVariable: 'HARBOR_USERNAME')]) {
// 执行远程命令
sshPublisher(publishers: [sshPublisherDesc(configName: "${HOST_NAME}", transfers: [sshTransfer(
cleanRemote: false, excludes: '', execCommand: "sh -x /opt/jenkins/springboot/deployment.sh ${HARBOR_USERNAME} ${HARBOR_PASSWORD} ${IMAGE_NAME} ${IMAGE_APP}",
execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/opt/jenkins/springboot',
remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'deployment.sh')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false
)])
}
echo '部署项目完成'
}
}
}
post {
always {
echo '开始发送邮件通知'
emailext(
subject: '构建通知:${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!',
body: '${FILE,path="email.html"}',
to: 'cuiliang0302@qq.com'
)
echo '邮件通知发送完成'
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/luzhijun2023/sprint_boot_demo.git
git@gitee.com:luzhijun2023/sprint_boot_demo.git
luzhijun2023
sprint_boot_demo
sprint-boot-demo
master

搜索幫助