MeterSphere/Jenkinsfile

148 lines
7.0 KiB
Plaintext
Raw Normal View History

2023-09-14 09:32:41 +08:00
#!groovy
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 {
2023-08-10 09:20:25 +08:00
pollSCM('50 * * * *')
2022-08-20 19:41:03 +08:00
}
2022-10-10 13:41:39 +08:00
environment {
2024-05-07 10:19:39 +08:00
IMAGE_PREFIX = 'registry.fit2cloud.com/metersphere'
2023-05-25 13:34:13 +08:00
IMAGE_NAME = 'metersphere'
2023-09-22 15:11:10 +08:00
JAVA_HOME = '/opt/jdk-21'
2020-12-18 11:57:58 +08:00
}
stages {
stage('Preparation') {
steps {
script {
REVISION = ""
2022-10-10 13:41:39 +08:00
BUILD_SDK = false
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
}
2022-10-17 13:41:22 +08:00
if (params.frontendLink != null && !params.frontendLink.equals("")) {
env.FRONTEND_LINK = params.frontendLink
}
env.REVISION = "${REVISION}"
2022-10-10 13:41:39 +08:00
env.BUILD_SDK = "${BUILD_SDK}"
echo "REVISION=${REVISION}, BUILD_SDK=${BUILD_SDK}"
2022-10-10 13:41:39 +08:00
}
}
}
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
2023-09-22 15:11:10 +08:00
export JAVA_HOME=/opt/jdk-21
2022-10-10 13:41:39 +08:00
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
2023-05-18 14:00:05 +08:00
export PATH=$JAVA_HOME/bin:/opt/apache-maven-3.8.3/bin:$PATH
2022-10-10 13:41:39 +08:00
java -version
2024-04-19 12:46:20 +08:00
./mvnw deploy -N -Drevision=${REVISION} --settings ./settings.xml
./mvnw clean deploy -Drevision=${REVISION} -DskipTests -DskipAntRunForJenkins -pl !app --file backend/pom.xml --settings ./settings.xml
2022-10-10 13:41:39 +08:00
'''
}
}
}
2020-12-18 11:57:58 +08:00
stage('Build/Test') {
when { environment name: 'BUILD_SDK', 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
2023-09-22 15:11:10 +08:00
export JAVA_HOME=/opt/jdk-21
2022-03-17 19:40:17 +08:00
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
2023-05-18 14:00:05 +08:00
export PATH=$JAVA_HOME/bin:/opt/apache-maven-3.8.3/bin:$PATH
2022-03-17 19:40:17 +08:00
java -version
2024-02-23 14:36:11 +08:00
# 删除本地缓存
LOCAL_REPOSITORY=$(./mvnw help:evaluate -Dexpression=settings.localRepository --settings ./settings.xml -q -DforceStdout)
2024-02-23 14:36:11 +08:00
rm -rf $LOCAL_REPOSITORY/io/metersphere/metersphere-jmeter-assertions/*
rm -rf $LOCAL_REPOSITORY/io/metersphere/metersphere-jmeter-functions/*
2024-04-19 12:46:20 +08:00
./mvnw clean install -Drevision=${REVISION} -DskipTests --settings ./settings.xml
2023-06-02 15:47:53 +08:00
mkdir -p backend/app/target/dependency && (cd backend/app/target/dependency && jar -xf ../*.jar);
2022-03-17 19:40:17 +08:00
'''
2020-12-18 11:57:58 +08:00
}
}
}
stage('Community build & push') {
when { environment name: 'BUILD_SDK', value: 'false' }
2020-12-18 11:57:58 +08:00
steps {
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
sh '''#!/bin/bash -xe
export JAVA_HOME=/opt/jdk-21
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:/opt/apache-maven-3.8.3/bin:$PATH
2024-04-19 12:46:20 +08:00
LOCAL_REPOSITORY=$(./mvnw help:evaluate -Dexpression=settings.localRepository --settings ./settings.xml -q -DforceStdout)
libraries=('general-xpack-impl')
for library in "${libraries[@]}";
do
cp -rf $LOCAL_REPOSITORY/io/metersphere/$library/${REVISION}/$library-${REVISION}.jar backend/app/target/dependency/BOOT-INF/lib/
done
2024-05-07 10:19:39 +08:00
docker --config /home/metersphere/.docker buildx build --no-cache --build-arg MS_VERSION=\${TAG_NAME:-\$BRANCH_NAME}-\${GIT_COMMIT:0:8} -t ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME}-community --platform linux/amd64,linux/arm64 . --push
'''
}
}
}
stage('Enterprise build & push') {
when { environment name: 'BUILD_SDK', value: 'false' }
steps {
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
sh '''#!/bin/bash -xe
export JAVA_HOME=/opt/jdk-21
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:/opt/apache-maven-3.8.3/bin:$PATH
java -version
2024-04-19 12:46:20 +08:00
LOCAL_REPOSITORY=$(./mvnw help:evaluate -Dexpression=settings.localRepository --settings ./settings.xml -q -DforceStdout)
# echo $LOCAL_REPOSITORY
libraries=('metersphere-api-test-impl' 'metersphere-load-test-impl' 'general-xpack-impl')
for library in "${libraries[@]}";
do
cp -rf $LOCAL_REPOSITORY/io/metersphere/$library/${REVISION}/$library-${REVISION}.jar backend/app/target/dependency/BOOT-INF/lib/
#
rm -rf $LOCAL_REPOSITORY/io/metersphere/$library/${REVISION}/target/lib/*
2024-04-19 12:46:20 +08:00
./mvnw dependency:copy-dependencies -DincludeScope=runtime --file $LOCAL_REPOSITORY/io/metersphere/$library/${REVISION}/$library-${REVISION}.pom --settings ./settings.xml
cp -rf $LOCAL_REPOSITORY/io/metersphere/$library/${REVISION}/target/lib/* backend/app/target/dependency/BOOT-INF/lib/
done
2024-05-07 10:19:39 +08:00
docker --config /home/metersphere/.docker buildx build --no-cache --build-arg MS_VERSION=\${TAG_NAME:-\$BRANCH_NAME}-\${GIT_COMMIT:0:8} -t ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME}-enterprise --platform linux/amd64,linux/arm64 . --push
'''
}
2020-12-18 11:57:58 +08:00
}
}
2023-11-10 14:44:32 +08:00
stage('Build Standalone') {
when {
expression {
def reg = "^\\d+\\.\\w+\$"
2023-11-10 15:18:33 +08:00
return env.REVISION.matches(reg) && env.BUILD_SDK == 'false'
2023-11-10 14:44:32 +08:00
}
}
steps {
script {
2024-04-15 19:26:30 +08:00
build job: "../metersphere-standalone/${BRANCH_NAME}", quietPeriod: 10, wait: false
2023-11-10 14:44:32 +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-18 11:57:58 +08:00
}
}