Files
EasySoft-ZenTaoPMS/misc/ci/Jenkinsfile
T
2023-12-18 14:36:56 +08:00

604 lines
23 KiB
Groovy

library 'z-common@feat-231130'
library 'z-zentaopms@feat-231204'
pipeline {
agent {
kubernetes {
inheritFrom "xuanim"
yamlFile 'misc/ci/normal.yaml'
}
}
options {
skipDefaultCheckout()
parallelsAlwaysFailFast()
overrideIndexTriggers(false)
quietPeriod 900
}
parameters {
separator(name: "action", sectionHeader: "构建动作")
choice choices: ['auto', 'snapshot', 'release'], description: '构建包类型(快照或发版)', name: 'build_kind'
booleanParam defaultValue: true, description: '制作开源版', name: 'publish_open'
booleanParam defaultValue: true, description: '制作企业版', name: 'publish_biz'
booleanParam defaultValue: false, description: '制作SAFe插件', name: 'publish_plugin_safe'
booleanParam defaultValue: true, description: '制作镜像', name: 'publish_image'
booleanParam defaultValue: true, description: '制作一键安装包', name: 'publish_zbox'
separator(name: "replay", sectionHeader: "仓库切换")
string description: '指定一个构建Id用于回放', name: 'REPLAY_ID', trim: true
string description: '指定 zentaoext 分支, 也可以是 tag 或者 commit', name: 'zentaoext_version', trim: true
string description: '指定 xuanxuan 分支', name: 'xuanxuan_version', trim: true
string description: '指定 zdoo 分支', name: 'zdoo_version', trim: true
string description: '指定 zdooext 分支', name: 'zdooext_version', trim: true
string description: '指定全量降级 revision', name: 'fulldown_version', trim: true
separator(name: "other", sectionHeader: "其它")
booleanParam defaultValue: false, description: '调试模式', name: 'DEBUG'
}
environment {
TZ="Asia/Shanghai"
ZENTAO_RELEASE_PATH = "${WORKSPACE}/release"
XUANXUAN_SRC_PATH = "${WORKSPACE}/xuansrc"
SRC_ZDOO_PATH = "${WORKSPACE}/zdoo"
SRC_ZDOOEXT_PATH = "${WORKSPACE}/zdooext"
SRC_ZENTAOEXT_PATH = "${WORKSPACE}/zentaoext"
MIRROR = "true"
// 默认从job参数里读取,打开后覆盖
PUBLISH_ZIP = "${params.publish_zip}"
PUBLISH_IMAGE = "${params.publish_image}"
PUBLISH_ZBOX = "${params.publish_zbox}"
}
stages {
stage("Basic Build") {
when {
anyOf {
buildingTag()
not {
triggeredBy 'BranchEventCause'
}
}
}
agent {
kubernetes {
inheritFrom "zentao-package build-docker xuanim"
yamlFile 'misc/ci/basic-build.yaml'
}
}
stages {
stage("Pull pms") {
steps {
checkout scm
script {
def triggeredBy = currentBuild.getBuildCauses()
println "Build triggered by: ${triggeredBy}"
env.GIT_URL = sh(returnStdout: true, script: 'git config --get remote.origin.url').trim()
env.GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
def j = job.newJob()
env.GIT_BRANCH = j.getBranchById(env.GIT_COMMIT)
zentaopms.setupStaticEnv()
zentaopms.setupEnvAfterCheckout()
zCheckout([
[name: "xuansrc", subDir: true, url: "https://${env.GIT_HOST}/easycorp/xuanxuan.git", credentialsId: "git-jenkins-bot-http", branchs: ["${params.xuanxuan_version}", j.getReplaySHA("xuanxuan"), "${env.XUANVERSION}"] ],
[name: "zdoo", subDir: true, url: "https://${env.GIT_HOST}/easycorp/zdoo.git", credentialsId: "git-jenkins-bot-http", branchs: ["${params.zdoo_version}", j.getReplaySHA("zdoo"), "${env.ZDOO_VERSION}"] ],
[name: "zdooext", subDir: true, url: "https://${env.GIT_HOST}/easycorp/zdooext.git", credentialsId: "git-jenkins-bot-http", branchs: ["${params.zdooext_version}", j.getReplaySHA("zdooext"), "${env.ZDOOEXT_VERSION}"] ],
[name: "zentaoext", subDir: true, url: "https://${env.GIT_HOST}/${env.ZENTAOEXT_GIT_REPO}.git", credentialsId: "git-jenkins-bot-http", branchs: ["${params.zentaoext_version}", j.getReplaySHA("zentaoext"), "${env.ZENTAOEXT_VERSION}"] ],
[name: "downRepo", subDir: true, url: "https://${env.GIT_HOST}/${env.DOWNGRADE_GIT_REPO}.git", credentialsId: "git-jenkins-bot-http", branchs: ["${params.fulldown_version}", j.getReplaySHA("${env.DOWNGRADE_GIT_REPO}"), "downgrade/release-18.10/src"] ]
])
zentaopms.setupEnvAfterCheckoutExt()
}
}
}
stage("Setup Global Env") {
steps {
sh 'env'
script {
def j = job.newJob()
j.SaveHeadReport('./.head.md')
// update custom envoronment here
// send start msg
def mdPath = "start.md"
j.SaveStartReport(mdPath)
ximNotify(title: "开始构建禅道", contentFile: mdPath, contentHeaderFile: './.head.md')
}
}
}
stage("Build") {
when { expression { return params.publish_open || params.publish_biz } }
stages {
stage("增量降级") {
steps {
echo "GIT_BRANCH in jenkinsfile is ${env.GIT_BRANCH}"
script { downgrade.increase() }
}
post {
failure {
script { downgrade.increaseErrReport() }
}
}
}
stage("make ciCommon") {
steps {
withCredentials([gitUsernamePassword(credentialsId: 'git-jenkins-bot-http',gitToolName: 'git-tool')]) {
container('package') {
sh 'mkdir -pv ${ZENTAO_RELEASE_PATH} && chown 1000:1000 ${ZENTAO_RELEASE_PATH}'
sh 'git config --global pull.ff only'
//sh 'cp -av ${ZENTAO_BUILD_PATH}/adminer www/'
sh 'pwd && ls -l && make ciCommon'
sh 'ls -l ${ZENTAO_RELEASE_PATH}'
}
}
}
}
stage("zentaoext") {
when { expression { return params.publish_biz } }
steps {
container('package') {
sh 'cd $SRC_ZENTAOEXT_PATH && make'
sh 'cp ${ZENTAO_BUILD_PATH}/zentao*.zip ./'
sh 'cp ${ZENTAO_BUILD_PATH}/docker/Dockerfile.release.ext ./Dockerfile.release.ext'
}
container('docker') {
sh 'docker build --pull -t ${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG} -f Dockerfile.release.ext ${ZENTAO_RELEASE_PATH}'
sh 'docker push ${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}'
}
script {
buildPkg.uploadSource()
env.PLUGIN_SAFE_EXIST = sh(returnStatus: true, script: 'test -d $SRC_ZENTAOEXT_PATH/zentaopro/safe')
}
}
}
stage("SAFe") {
when {
allOf {
expression { return params.publish_biz || params.publish_plugin_safe }
environment name: 'PLUGIN_SAFE_EXIST', value: '0'
}
}
steps {
container('package') {
sh '''${ZENTAO_BUILD_PATH}/script/downgrade/dirDowngrade.sh -n safe -s -i \
-p 8.1,7.2,7.1,7.0,5.4 \
-c ${PWD}/misc -r $SRC_ZENTAOEXT_PATH/zentaopro -o ${ZENTAO_BUILD_PATH} \
safe '''
sh 'cp -v ${ZENTAO_BUILD_PATH}/safe-*.zip ${ZENTAO_RELEASE_PATH}/'
sh 'cd $SRC_ZENTAOEXT_PATH && make safeDown'
}
script {
env.UPLOADED_PLUGIN_SAFE = 'true'
buildPkg.uploadSAFe(["php5.4_5.6", "php7.0", "php7.1", "php7.2_7.4", "php8.1"])
}
}
}
}
} // End Build
}
}
stage("Publish") {
environment {
OUTPUT_PKG_PATH = "${ZENTAO_RELEASE_PATH}/output"
QINIU_ACCESS_KEY = credentials('qiniu-upload-ak')
QINIU_SECRET_KEY = credentials('qiniu-upload-sk')
}
stages {
stage("Merge and Upload") {
when { expression { return params.publish_biz } }
matrix {
agent {
kubernetes {
containerTemplate {
name "package"
image "${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}"
command "sleep"
args "99d"
}
yamlFile 'misc/ci/publish-zip.yaml'
}
}
options {
skipDefaultCheckout()
}
axes {
axis {
name "ZLANG"
values "cn", "en"
}
axis {
name "PHPVERSION"
values "php5.4_5.6", "php7.0", "php7.1", "php7.2_7.4", "k8s.php7.2_7.4", "php8.1", "k8s.php8.1"
}
}
excludes {
exclude {
axis {
name 'ZLANG'
values 'en'
}
axis {
name "PHPVERSION"
values "k8s.php7.2_7.4", "k8s.php8.1"
}
}
}
stages {
stage("ZIP") {
environment {
ARTIFACT_NAME = """${sh(
returnStdout: true,
script: 'test ${ZLANG} = cn && echo -n ZenTaoPMS || echo -n ZenTaoALM'
).trim()}"""
INT_FLAG = """${sh(
returnStdout: true,
script: 'test ${ZLANG} = cn && echo -n "int." || echo -n ""'
).trim()}"""
}
stages {
stage("package zip") {
steps{
echo "${env.ZLANG} <=> ${env.PHPVERSION}"
container('package') {
sh 'mkdir $ZENTAO_RELEASE_PATH'
sh '${ZENTAO_BUILD_PATH}/package.sh zip'
sh 'mkdir $OUTPUT_PKG_PATH'
}
}
}
stage("upload zip") {
steps {
sh 'mkdir ${OUTPUT_PKG_PATH}/${PMS_VERSION}'
sh 'cp ${ZENTAO_RELEASE_PATH}/base.zip ${OUTPUT_PKG_PATH}/${PMS_VERSION}/${ARTIFACT_NAME}-${PMS_VERSION}-${PHPVERSION}.zip'
script {
buildPkg.uploadPMS(env.PHPVERSION)
// copy php7.2 as php8.0
if (env.PHPVERSION=="php7.2_7.4") {
buildPkg.uploadPMS('php8.0')
sh 'cp ${ZENTAO_RELEASE_PATH}/base.zip ${OUTPUT_PKG_PATH}/${PMS_VERSION}/${ARTIFACT_NAME}-${PMS_VERSION}-php8.0.zip'
}
buildPkg.uploadExt()
}
}
} // End upload zip
stage("syspack") {
when {
environment name: 'BUILD_KIND', value: 'release'
}
steps{
script {
buildPkg.buildRpmAndDeb()
}
}
}
stage("Upload Qiniu") {
when {
environment name: 'BUILD_KIND', value: 'release'
}
steps {
sh 'ls -l ${OUTPUT_PKG_PATH}'
container('jnlp') {
sh 'qshell account $QINIU_ACCESS_KEY $QINIU_SECRET_KEY uploader'
sh 'qshell qupload2 --bucket $QINIU_BUCKET --overwrite --src-dir $OUTPUT_PKG_PATH --key-prefix $OBJECT_KEY_PREFIX'
}
}
}
} // end stages
} // end stage frame
} // End matrix stages
} // End matrix
} // End Merge and Upload Max
stage("Notice ZIP") {
when { expression { return params.publish_biz } }
steps {
checkout scmGit(branches: [[name: "master"]],
extensions: [cloneOption(depth: 2, noTags: false, reference: '', shallow: true)],
userRemoteConfigs: [[credentialsId: 'git-jenkins-bot-http', url: "https://${env.GIT_HOST}/devops/zentao-package.git"]]
)
container('xuanimbot') {
sh './gen_build_report.sh > success.md'
}
script {
def j = job.newJob()
j.SaveHeadReport('./.head.md')
ximNotify(title: "禅道源码包构建成功", contentFile: "success.md", contentHeaderFile: './.head.md')
}
}
}
stage("Zbox") {
when { expression { return params.publish_zbox } }
environment {
// printf "$PKG_URL_FORMATTER" pmsPack ZenTaoPMS 18.5 ZenTaoPMS-18.5-php8.1.zip
PKG_URL_FORMATTER = """${sh(
returnStdout: true,
script: "echo ${ARTIFACT_PROTOCOL}://${ARTIFACT_HOST}/repository/${ARTIFACT_REPOSITORY}/zentao/%s/`echo ${ARTIFACT_SUBGROUP} | tr . /`/%s/%s/%s"
).trim()}"""
}
stages {
stage("Package") {
parallel {
stage("Zbox win") {
agent {
kubernetes {
yamlFile 'misc/ci/publish-zbox.yaml'
}
}
stages() {
stage("Prepare") {
steps {
checkout scmGit(branches: [[name: "main"]],
extensions: [cloneOption(depth: 2, noTags: false, reference: '', shallow: true)],
userRemoteConfigs: [[credentialsId: 'git-jenkins-bot-http', url: "https://${env.GIT_HOST}/devops/zbox-builder.git"]]
)
}
}
stage("Build") {
steps {
script {
buildZboxWin.doBuild()
buildZboxWin.uploadInternal()
}
}
}
stage("Upload Qiniu") {
when {
environment name: 'BUILD_KIND', value: 'release'
}
steps {
container('docker') {
sh 'mkdir -pv ./release/upload && cd ./release/upload && mkdir $PMS_VERSION $BIZ_VERSION $MAX_VERSION $IPD_VERSION'
sh "mv `find release/zh-cn/$PMS_VERSION release/en/$PMS_VERSION -type f -name 'ZenTao*.exe'` release/upload/$PMS_VERSION"
sh "mv `find release/zh-cn/$BIZ_VERSION release/en/$BIZ_VERSION -type f -name 'ZenTao*.exe'` release/upload/$BIZ_VERSION"
sh "mv `find release/zh-cn/$MAX_VERSION release/en/$MAX_VERSION -type f -name 'ZenTao*.exe'` release/upload/$MAX_VERSION"
sh "mv `find release/zh-cn/$IPD_VERSION release/en/$IPD_VERSION -type f -name 'ZenTao*.exe'` release/upload/$IPD_VERSION"
}
container('jnlp') {
sh 'qshell account $QINIU_ACCESS_KEY $QINIU_SECRET_KEY uploader'
sh 'qshell qupload2 --bucket $QINIU_BUCKET --overwrite --src-dir ./release/upload --key-prefix $OBJECT_KEY_PREFIX'
}
}
} // End Upload Qiniu
}
} // End Zbox win
stage("Zbox linux") {
agent {
kubernetes {
yamlFile 'misc/ci/publish-zbox.yaml'
}
}
stages() {
stage("Prepare") {
steps {
checkout scmGit(branches: [[name: "main"]],
extensions: [cloneOption(depth: 2, noTags: false, reference: '', shallow: true)],
userRemoteConfigs: [[credentialsId: 'git-jenkins-bot-http', url: "https://${env.GIT_HOST}/devops/zbox-builder.git"]]
)
}
}
stage("Build") {
steps {
script {
buildZboxLinux.doBuild()
buildZboxLinux.uploadInternal()
}
}
}
stage("Upload Qiniu") {
when {
environment name: 'BUILD_KIND', value: 'release'
}
steps {
container('docker') {
sh 'mkdir -pv ./release/upload && cd ./release/upload && mkdir $PMS_VERSION $BIZ_VERSION $MAX_VERSION $IPD_VERSION'
sh "mv `find release/zh-cn/$PMS_VERSION release/en/$PMS_VERSION -type f -name 'ZenTao*'` release/upload/$PMS_VERSION"
sh "mv `find release/zh-cn/$BIZ_VERSION release/en/$BIZ_VERSION -type f -name 'ZenTao*'` release/upload/$BIZ_VERSION"
sh "mv `find release/zh-cn/$MAX_VERSION release/en/$MAX_VERSION -type f -name 'ZenTao*'` release/upload/$MAX_VERSION"
sh "mv `find release/zh-cn/$IPD_VERSION release/en/$IPD_VERSION -type f -name 'ZenTao*'` release/upload/$IPD_VERSION"
}
container('jnlp') {
sh 'qshell account $QINIU_ACCESS_KEY $QINIU_SECRET_KEY uploader'
sh 'qshell qupload2 --bucket $QINIU_BUCKET --overwrite --src-dir ./release/upload --key-prefix $OBJECT_KEY_PREFIX'
}
}
} // End Upload Qiniu
}
} // End Zbox linux
} // End parallel
}
stage("Notice zbox") {
steps {
checkout scmGit(branches: [[name: "main"]],
extensions: [cloneOption(depth: 2, noTags: false, reference: '', shallow: true)],
userRemoteConfigs: [[credentialsId: 'git-jenkins-bot-http', url: "https://${env.GIT_HOST}/devops/zbox-builder.git"]]
)
sh 'script/lib/gen_report.sh > zbox-success.md'
script {
def j = job.newJob()
j.SaveHeadReport('./.head.md')
ximNotify(title: "禅道一键安装包构建成功", contentFile: "zbox-success.md", contentHeaderFile: './.head.md')
}
}
}
}
} // End Zbox
stage("Docker Image") {
when { expression { return params.publish_image } }
agent {
kubernetes {
inheritFrom "dind2 xuanim"
yamlFile 'misc/ci/publish-image.yaml'
}
}
environment {
CI_BUILD_PUBLIC_IMAGE="true"
PKG_URL_FORMATTER = """${sh(
returnStdout: true,
script: "echo ${ARTIFACT_PROTOCOL}://${ARTIFACT_HOST}/repository/${ARTIFACT_REPOSITORY}/zentao/%s/`echo ${ARTIFACT_SUBGROUP} | tr . /`/%s/%s/%s"
).trim()}"""
INSTALL_GOSS_TOOLS="true"
DEBUG="0" // set to int for dgoss
}
steps {
checkout scmGit(branches: [[name: "master"]],
extensions: [cloneOption(depth: 2, noTags: false, reference: '', shallow: true)],
userRemoteConfigs: [[credentialsId: 'git-jenkins-bot-http', url: "https://${env.GIT_HOST}/app/zentao.git"]]
)
script {
dockerBuildx(host=env.REGISTRY_HOST, credentialsId=env.DOCKER_CREDENTIALS_ID) {
stage("prepare") {
sh "apk --no-cache add curl make bash jq git tzdata"
sh "make markdown-init"
}
stage("docker build") {
sh 'make test-open'
sh 'make build'
sh 'make test-biz'
sh 'make build-biz'
sh 'make test-biz-k8s'
sh 'make build-biz-k8s'
sh 'make test-max'
sh 'make build-max'
sh 'make test-max-k8s'
sh 'make build-max-k8s'
sh 'make test-ipd'
sh 'make build-ipd'
sh 'make test-ipd-k8s'
sh 'make build-ipd-k8s'
sh 'make markdown-render > ./report.md'
}
}
}
script {
if (env.BUILD_KIND=='release') {
stage("离线镜像包") {
offlineImage.save()
offlineImage.release()
}
}
def j = job.newJob()
j.SaveHeadReport('./.head.md')
ximNotify(title: "禅道镜像构建成功", contentFile: "report.md", contentHeaderFile: './.head.md')
}
}
} // End Docker Image
stage("Upload rongpm") {
agent {
kubernetes {
inheritFrom "zentao-package xuanim"
yamlFile 'misc/ci/normal.yaml'
}
}
when {
allOf {
expression { return params.publish_biz }
environment name:'BUILD_KIND', value:'release'
}
beforeAgent true
}
steps {
script {
checkout scmGit(branches: [[name: "master"]],
extensions: [cloneOption(depth: 2, noTags: false, reference: '', shallow: true)],
userRemoteConfigs: [[credentialsId: 'git-jenkins-bot-http', url: "https://${env.GIT_HOST}/web/rongpm.git"]]
)
container('package') {
sh 'mkdir -p output/rongpm/${PMS_VERSION}'
sh 'cd output/rongpm/${PMS_VERSION} && php7.2 $WORKSPACE/system/bin/buildpractice.php && rm -rf rongpm'
}
container('jnlp') {
sh 'qshell account $QINIU_ACCESS_KEY $QINIU_SECRET_KEY uploader'
sh 'qshell qupload2 --bucket $QINIU_BUCKET --overwrite --src-dir ./output --key-prefix $OBJECT_KEY_PREFIX'
}
}
}
} // End Upload rongpm
}
} // end publish
}
post {
failure {
ximNotify(title: "禅道构建失败", content: "请点击查看详情")
}
}
}