2020-12-18 11:57:58 +08:00
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
node {
|
2022-05-05 22:07:46 +08:00
|
|
|
label 'metersphere'
|
2020-12-18 11:57:58 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-20 19:41:03 +08:00
|
|
|
triggers {
|
2022-10-28 18:09:47 +08:00
|
|
|
pollSCM('0 1 * * *')
|
2022-08-20 19:41:03 +08:00
|
|
|
}
|
2022-10-10 13:41:39 +08:00
|
|
|
environment {
|
2021-01-05 17:25:24 +08:00
|
|
|
IMAGE_PREFIX = 'registry.cn-qingdao.aliyuncs.com/metersphere'
|
2022-11-25 08:51:52 +08:00
|
|
|
JAVA_HOME = '/opt/jdk-17'
|
2020-12-18 11:57:58 +08:00
|
|
|
}
|
|
|
|
stages {
|
2022-07-22 19:26:34 +08:00
|
|
|
stage('Preparation') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
REVISION = ""
|
2022-10-10 13:41:39 +08:00
|
|
|
BUILD_SDK = false
|
|
|
|
BUILD_PARENT = false
|
2022-07-22 19:26:34 +08:00
|
|
|
if (env.BRANCH_NAME.startsWith("v") ) {
|
|
|
|
REVISION = env.BRANCH_NAME.substring(1)
|
|
|
|
} else {
|
|
|
|
REVISION = env.BRANCH_NAME
|
|
|
|
}
|
2022-10-10 13:41:39 +08:00
|
|
|
if (params.buildSdk) {
|
|
|
|
BUILD_SDK = true
|
|
|
|
}
|
|
|
|
if (params.buildParent) {
|
|
|
|
BUILD_PARENT = true
|
|
|
|
}
|
2022-10-17 13:41:22 +08:00
|
|
|
if (params.frontendLink != null && !params.frontendLink.equals("")) {
|
|
|
|
env.FRONTEND_LINK = params.frontendLink
|
|
|
|
}
|
2022-07-22 19:26:34 +08:00
|
|
|
env.REVISION = "${REVISION}"
|
2022-10-10 13:41:39 +08:00
|
|
|
env.BUILD_SDK = "${BUILD_SDK}"
|
|
|
|
env.BUILD_PARENT = "${BUILD_PARENT}"
|
|
|
|
echo "REVISION=${REVISION}, BUILD_SDK=${BUILD_SDK}, BUILD_PARENT=${BUILD_PARENT}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('POM') {
|
|
|
|
when { environment name: 'BUILD_PARENT', value: 'true' }
|
|
|
|
steps {
|
2022-10-27 14:54:43 +08:00
|
|
|
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
|
2022-10-10 13:41:39 +08:00
|
|
|
sh '''#!/bin/bash -xe
|
2022-11-25 08:51:52 +08:00
|
|
|
export JAVA_HOME=/opt/jdk-17
|
2022-10-10 13:41:39 +08:00
|
|
|
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
|
|
|
|
export PATH=$JAVA_HOME/bin:$PATH
|
|
|
|
java -version
|
|
|
|
./mvnw install -N -Drevision=${REVISION} --settings ./settings.xml
|
|
|
|
'''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('SDK') {
|
|
|
|
when { environment name: 'BUILD_SDK', value: 'true' }
|
|
|
|
steps {
|
2022-10-27 14:54:43 +08:00
|
|
|
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
|
2022-10-10 13:41:39 +08:00
|
|
|
sh '''#!/bin/bash -xe
|
2022-11-25 08:51:52 +08:00
|
|
|
export JAVA_HOME=/opt/jdk-17
|
2022-10-10 13:41:39 +08:00
|
|
|
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
|
|
|
|
export PATH=$JAVA_HOME/bin:$PATH
|
|
|
|
java -version
|
|
|
|
./mvnw install -N -Drevision=${REVISION} --settings ./settings.xml
|
2022-11-11 21:37:53 +08:00
|
|
|
./mvnw clean install -Drevision=${REVISION} -pl framework,framework/sdk-parent,framework/sdk-parent/domain,framework/sdk-parent/sdk,framework/sdk-parent/xpack-interface,framework/sdk-parent/jmeter --settings ./settings.xml
|
2022-10-15 06:49:01 +08:00
|
|
|
|
|
|
|
# 复制前端代码
|
2022-10-15 19:36:13 +08:00
|
|
|
if [ -n "${FRONTEND_LINK}" ]; then
|
2022-10-15 11:58:06 +08:00
|
|
|
cp -r framework/sdk-parent/frontend ${FRONTEND_LINK}/frontend/.tmp_npm
|
2022-10-15 06:49:01 +08:00
|
|
|
fi
|
2022-10-10 13:41:39 +08:00
|
|
|
'''
|
2022-07-22 19:26:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 11:57:58 +08:00
|
|
|
stage('Build/Test') {
|
2022-10-10 13:41:39 +08:00
|
|
|
when {
|
|
|
|
allOf {
|
|
|
|
environment name: 'BUILD_SDK', value: 'false';
|
|
|
|
environment name: 'BUILD_PARENT', value: 'false'
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 11:57:58 +08:00
|
|
|
steps {
|
2022-10-27 14:54:43 +08:00
|
|
|
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
|
2022-10-10 13:41:39 +08:00
|
|
|
sh '''#!/bin/bash -xe
|
2022-11-25 08:51:52 +08:00
|
|
|
export JAVA_HOME=/opt/jdk-17
|
2022-03-17 19:40:17 +08:00
|
|
|
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
|
2022-10-10 13:41:39 +08:00
|
|
|
export PATH=$JAVA_HOME/bin:$PATH
|
2022-03-17 19:40:17 +08:00
|
|
|
java -version
|
2022-10-11 11:15:44 +08:00
|
|
|
./mvnw clean package -Drevision=${REVISION} --settings ./settings.xml
|
2022-10-10 13:41:39 +08:00
|
|
|
|
|
|
|
frameworks=('framework/eureka' 'framework/gateway')
|
|
|
|
for library in "${frameworks[@]}";
|
|
|
|
do
|
|
|
|
mkdir -p $library/target/dependency && (cd $library/target/dependency; jar -xf ../*.jar)
|
|
|
|
done
|
|
|
|
|
|
|
|
LOCAL_REPOSITORY=$(./mvnw help:evaluate -Dexpression=settings.localRepository --settings ./settings.xml -q -DforceStdout)
|
|
|
|
|
2022-12-07 15:03:22 +08:00
|
|
|
libraries=('api-test' 'performance-test' 'project-management' 'system-setting' 'test-track' 'report-stat' 'workstation')
|
2022-10-10 13:41:39 +08:00
|
|
|
for library in "${libraries[@]}";
|
|
|
|
do
|
|
|
|
mkdir -p $library/backend/target/dependency && (cd $library/backend/target/dependency; jar -xf ../*.jar; cp $LOCAL_REPOSITORY/io/metersphere/metersphere-xpack/${REVISION}/metersphere-xpack-${REVISION}.jar ./BOOT-INF/lib/)
|
|
|
|
done
|
2022-03-17 19:40:17 +08:00
|
|
|
'''
|
2020-12-18 11:57:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Docker build & push') {
|
2022-10-10 13:41:39 +08:00
|
|
|
when {
|
|
|
|
allOf {
|
|
|
|
environment name: 'BUILD_SDK', value: 'false';
|
|
|
|
environment name: 'BUILD_PARENT', value: 'false'
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 11:57:58 +08:00
|
|
|
steps {
|
2022-10-10 13:41:39 +08:00
|
|
|
script {
|
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
try {
|
|
|
|
sh '''#!/bin/bash -xe
|
|
|
|
cd ${WORKSPACE}
|
2022-12-07 15:03:22 +08:00
|
|
|
libraries=('framework/eureka' 'framework/gateway' 'api-test' 'performance-test' 'project-management' 'report-stat' 'system-setting' 'test-track' 'workstation')
|
2022-10-10 13:41:39 +08:00
|
|
|
for library in "${libraries[@]}";
|
|
|
|
do
|
|
|
|
IMAGE_NAME=${library#*/}
|
|
|
|
docker --config /home/metersphere/.docker buildx build --build-arg MS_VERSION=\${TAG_NAME:-\$BRANCH_NAME}-\${GIT_COMMIT:0:8} -t ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME} --platform linux/amd64,linux/arm64 ./$library --push
|
|
|
|
done
|
|
|
|
'''
|
|
|
|
break
|
|
|
|
} catch (Exception e) {
|
|
|
|
sleep 10
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 11:57:58 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-21 14:06:32 +08:00
|
|
|
}
|
|
|
|
post('Notification') {
|
|
|
|
always {
|
|
|
|
sh "echo \$WEBHOOK\n"
|
2022-10-26 15:47:28 +08:00
|
|
|
withCredentials([string(credentialsId: 'wechat-bot-webhook', variable: 'WEBHOOK')]) {
|
|
|
|
qyWechatNotification failNotify: true, mentionedId: '', mentionedMobile: '', webhookUrl: "$WEBHOOK"
|
|
|
|
}
|
2020-12-21 10:43:12 +08:00
|
|
|
}
|
2020-12-18 11:57:58 +08:00
|
|
|
}
|
|
|
|
}
|