代码拉取完成,页面将自动刷新
同步操作将从 若依/RuoYi-Cloud 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
pipeline {
agent {
label 'maven'
}
parameters {
string(name: 'Environments', defaultValue: 'dev', description: '支持的发布环境:dev,test,prod')
string(name: 'ServicesBuild', defaultValue: 'no', description: '构建镜像,支持单选和多选,选项有:ruoyi-system,ruoyi-gen,ruoyi-job,ruoyi-file,ruoyi-monitor,ruoyi-gateway,ruoyi-auth,all,no')
string(name: 'MultiServicesDeploy', defaultValue: 'no', description: '发布服务,支持单选和多选,选项有:ruoyi-system,ruoyi-gen,ruoyi-job,ruoyi-file,ruoyi-monitor,ruoyi-gateway,ruoyi-auth,all,no')
string(name: 'DeployVersion', defaultValue: 'no', description: '发布的镜像版本,该选项用在 test 和 prod 环境')
}
environment {
HARBOR_CREDENTIAL_ID = 'harbor-id'
GITLAB_CREDENTIAL_ID = 'gitlab-id'
KUBECONFIG_CREDENTIAL_ID = 'kube-id'
REGISTRY = 'harbor.yunzhicloud.com:3443'
DOCKERHUB_NAMESPACE = 'ruoyi'
K8S_NAMESPACE = 'unify-user'
BUILD_VERSION = sh(script:"echo `date +%s`", returnStdout: true).trim()
// 可以看出来,YAML中需要引用 parametes中的参数,只能写成 ${PROJECT_NAME} 这种形式。
// k8s YAML中如果要引用 environment中的参数,可以写成 $APP_NAME 这种形式。
}
stages {
stage ('拉取代码') {
agent none
when {
not {
equals expected: 'no', actual: params.ServicesBuild
}
}
steps {
echo "Current build version :: ${params.DeployVersion}"
echo "Current build version :: $BUILD_VERSION"
checkout(scm)
}
}
stage('初始化变量') {
agent none
steps {
container('maven') {
script {
//自由组合发布
if("${params.ServicesBuild}".trim() != "no") {
if("${params.ServicesBuild}".trim() == "all") {
ServicesBuild = 'ruoyi-system,ruoyi-gen,ruoyi-job,ruoyi-file,ruoyi-monitor,ruoyi-gateway,ruoyi-auth'
ServicesBuild = "${ServicesBuild}".split(",")
}else {
ServicesBuild = "${params.ServicesBuild}".split(",")
}
for (service in ServicesBuild) {
println "now docker build ${service}"
}
}
if("${params.MultiServicesDeploy}".trim() != "no") {
if("${params.MultiServicesDeploy}".trim() == "all") {
MultiServicesDeploy = 'ruoyi-system,ruoyi-gen,ruoyi-job,ruoyi-file,ruoyi-monitor,ruoyi-gateway,ruoyi-auth'
MultiServicesDeploy = "${MultiServicesDeploy}".split(",")
}else {
MultiServicesDeploy = "${params.MultiServicesDeploy}".split(",")
}
for (service in MultiServicesDeploy) {
println "now docker deploy ${service}"
}
}
}
}
}
}
stage('打包') {
agent none
when {
not {
equals expected: 'no', actual: params.ServicesBuild
}
}
steps {
container('maven') {
script {
sh "mvn -Dmaven.test.skip=true clean package"
// sh 'mvn -Dmaven.test.skip=true clean package -gs `pwd`/config/settings.xml'
}
}
}
}
stage('构建镜像') {
agent none
when {
not {
equals expected: 'no', actual: params.ServicesBuild
}
}
steps {
container('maven') {
script {
def branchedStages = [:]
for (service in ServicesBuild) {
// def workspace = "ruoyi-"
def workspace = ""
def svc = "${service}"
if("${svc}".trim() == "ruoyi-gateway" || "${svc}".trim() == "ruoyi-auth" || "${svc}".trim() == "ruoyi-admin"){
// workspace = "${workspace}" + "${svc}".trim().split("-")[1]
workspace = "${svc}"
}
if("${svc}".trim() == "ruoyi-system" || "${svc}".trim() == "ruoyi-gen" || "${svc}".trim() == "ruoyi-job" || "${svc}".trim() == "ruoyi-file"){
// workspace = "ruoyi-modules/" + "${workspace}" + "${svc}".trim().split("-")[1]
workspace = "ruoyi-modules/" + "${svc}"
}
if("${svc}".trim() == "ruoyi-monitor"){
// workspace = "ruoyi-visual/" + "${workspace}" + "${svc}".trim().split("-")[1]
workspace = "ruoyi-visual/" + "${svc}"
}
branchedStages["${svc} 镜像构建与推送"] = {
stage ("${svc}") {
// sh "docker build --build-arg workspace=${workspace} -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$svc:$BUILD_VERSION ."
sh "cd ${workspace} && docker build -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$svc:$BUILD_VERSION ."
withCredentials([usernamePassword(passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) {
sh 'echo "$HARBOR_PASSWORD" | docker login $REGISTRY -u "$HARBOR_USERNAME" --password-stdin'
sh "docker push $REGISTRY/$DOCKERHUB_NAMESPACE/${svc}:$BUILD_VERSION"
}
}
}
}
// Execute the stages in parallel
parallel branchedStages
}
}
}
}
stage('部署到服务') {
agent none
when {
not {
equals expected: 'no', actual: params.MultiServicesDeploy
}
}
steps {
container('maven') {
script {
def branchedStages = [:]
if ("${params.Environments}".trim() == "prod") {
input(id: 'deploy-to-prod', message: '@admin发布到正式环境吗?', submitter:'admin, lcj')
}
for (service in MultiServicesDeploy) {
def workspace = ""
def svc = "${service}"
if("${params.DeployVersion}".trim() != "no"){
env.DEPLOY_VERSION = "${params.DeployVersion}".trim()
}else{
env.DEPLOY_VERSION = "$BUILD_VERSION"
}
if("${svc}".trim() == "ruoyi-gateway" || "${svc}".trim() == "ruoyi-auth" || "${svc}".trim() == "ruoyi-admin"){
workspace = "${svc}".trim()
}
if("${svc}".trim() == "ruoyi-system" || "${svc}".trim() == "ruoyi-gen" || "${svc}".trim() == "ruoyi-job" || "${svc}".trim() == "ruoyi-file"){
workspace = "ruoyi-modules/" + "${svc}"
}
if("${svc}".trim() == "ruoyi-monitor"){
workspace = "ruoyi-visual/" + "${svc}"
}
branchedStages["${svc} 即将部署"] = {
stage ("即将部署的服务是 ${svc}") {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
variable: 'KUBECONFIG')
]) {
println "部署的版本: $DEPLOY_VERSION"
sh "envsubst < ${workspace}/deploy/service.yaml | kubectl apply -f -"
sh "envsubst < ${workspace}/deploy/deployment.yaml | kubectl apply -f -"
}
}
}
}
// Execute the stages in parallel
parallel branchedStages
}
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。