1、简介
KOCA标准门户流水线包含Admin门户、AMO门户、LCP门户
首先在git的koca-application仓库中按照规范创建如下内容
2、流水线的执行逻辑(以admin为例)
-
git clone koca-application/koca-deveops/koca-admin
-
编译koca-admin模块代码
-
数据库更新
-
编译bootapp并启动bootapp
-
清理npm缓存并编译部署web
-
更新nginx配置
3、运行效果
4、piperline
import hudson.model.*;
/**
* git克隆
* remoteAddr:仓库地址 如:http://ip:port/KOCA/koca-devops.git
* branch:git分支 如:refs/heads/develop
* credentialsId:git用户凭证
* dirName:git克隆在dirName目录下
*/
def gitClone(String remoteAddr, String branch, String credentialsId,String dirName) {
dir(dirName){
checkout([$class: 'GitSCM',
branches: [[name: (branch)]], doGenerateSubmoduleConfigurations: false,
extensions: [], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: (credentialsId), url: (remoteAddr)]]])
}
}
// admin前端模块清单V2
def webModules = [
"koca-front-web":[
"url":"http://ip/xxxx/koca-front.git",
'admin-basic': 'src/pc/modules/admin-basic',
'admin-workflow': 'src/pc/modules/admin-workflow',
'admin-report': 'src/pc/modules/admin-report',
'admin-batch-manager': 'src/pc/modules/admin-batch-manager',
'admin-file-manage': 'src/pc/modules/admin-file-manage',
'admin-jobschedule': 'src/pc/modules/admin-jobschedule',
'admin-biz-log': 'src/pc/modules/admin-biz-log',
'admin-view-module': 'src/pc/modules/admin-view-module',
'admin-dtc-manager': 'src/pc/modules/admin-dtc-manager',
'admin-common-confirm': 'src/pc/modules/admin-common-confirm',
'admin-backlog': 'src/pc/modules/admin-backlog',
'admin-business': 'src/pc/modules/admin-business',
'admin-video-chat': 'src/pc/modules/admin-video-chat',
'admin-app-access': 'src/pc/modules/admin-app-access',
'admin-document': 'src/pc/modules/admin-document',
'admin-oem': 'src/pc/modules/admin-oem',
'admin-message': 'src/pc/modules/admin-message',
'config-server': 'src/pc/modules/config-server',
'registry-manager': 'src/pc/modules/registry-manager',
'cli': 'src/tools/cli-v3',
'template': 'src/pc/template',
'config': 'src/pc/modules',
'ui': 'src/components/koca-ui-v2'
]
]
def kocaPlatform
def kocaGit
def kocaDb
def project
pipeline{
parameters{
booleanParam (defaultValue: false, description: '编译koca-admin代码', name: 'compile_koca_admin')
booleanParam (defaultValue: false, description: '编译时是否跳过测试', name: 'compile_skip_test')
choice(description: '选择数据库类型',name: 'selected_database',choices: ['oracle','mysql','mssql'])
booleanParam (defaultValue: false, description: '清空数据库', name: 'clean_database')
booleanParam (defaultValue: false, description: '数据库全量升级', name: 'all_database')
booleanParam (defaultValue: false, description: '数据库增量升级', name: 'update_database')
booleanParam (defaultValue: false, description: '编译Application代码并启动服务', name: 'startup_app')
booleanParam (defaultValue: false, description: '清理Npm缓存', name: 'clean_npm_cache')
booleanParam (defaultValue: false, description: '脚手架工具生成前端项目并编译启动', name: 'startup_web')
booleanParam (defaultValue: false, description: 'Nginx配置更新', name: 'update_nginx')
}
environment{
APPLICATION_LOCAL = 'koca-application/admin-msa';
PROJECT_YAML = 'koca-application/admin-msa/project.yaml';
DEFAULT_ENV = 'develop';
ADMIN_PATH = 'koca-admin';
}
agent{
node{
label 'Nodexxxxxx'
}
}
stages{
stage('拉取代码'){
steps{
script{
gitClone('http://ip/xxxxxx/koca-devops.git',"refs/heads/ci",'git-user','koca-devops')
// 下载bootapp
gitClone('http://ip/xxxxxx/koca-application.git',"refs/heads/${DEFAULT_ENV}",'git-user','koca-application')
// 下载admin源代码
gitClone('http://ip/xxxxxx/koca-admin.git',"refs/heads/${DEFAULT_ENV}",'git-user','koca-admin')
kocaPlatform = load 'koca-devops/kdop/kocaPlatform.groovy'
project = kocaPlatform.initProject("${PROJECT_YAML}")
}
}
}
stage('编译koca-admin代码'){
when{
expression{
return params.compile_koca_admin
}
}
steps{
script{
kocaPlatform.compileServer("${ADMIN_PATH}","install",params.compile_skip_test);
}
}
}
stage('更新数据库'){
when{
expression{
return params.clean_database || params.update_database || params.all_database
}
}
steps{
script{
kocaDb = load 'koca-devops/kdop/kocaDb.groovy'
def fromDatabase = kocaPlatform.getFromDatabase(project, params.selected_database)
def dbConnectMsg = kocaPlatform.getDbConnectMsg(fromDatabase, env.DEFAULT_ENV)
println(dbConnectMsg)
if (params.clean_database){
kocaDb.flywayCleanDb(dbConnectMsg)
}
if (params.update_database){
kocaDb.flywayUpdateDb(dbConnectMsg,fromDatabase)
}
if (params.all_database){
kocaDb.flywayAllDb(dbConnectMsg, fromDatabase)
}
}
}
}
stage('启动后台'){
when{
expression{
return params.startup_app
}
}
steps{
script{
dir("$APPLICATION_LOCAL"){
kocaPlatform.compileBootApps(project.servers)
kocaPlatform.startBootApps(project, params.selected_database,env.DEFAULT_ENV)
}
}
}
}
stage('清理Npm缓存'){
when{
expression{
return params.clean_npm_cache
}
}
steps{
script{
kocaPlatform.cleanNpmCache()
}
}
}
stage('编译启动web'){
when{
expression{
return params.startup_web
}
}
steps{
script{
kocaPlatform.compileWebFormSource(project,"/usr/local/nvm/versions/node/v14.21.2/bin","/opt/nginx","/usr/local/nvm","source",env.DEFAULT_ENV,"v2",webModules,false,"")
}
}
}
stage('更新nginx配置'){
steps{
script{
kocaPlatform.reloadNginx("$APPLICATION_LOCAL","/usr/local/nginx")
}
}
}
}
}