-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
71 lines (70 loc) · 3.15 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pipeline {
agent {
node {
label 'metersphere'
}
}
options {
quietPeriod(30)
}
environment {
BRANCH_NAME = "master"
}
stages {
stage('Preparation') {
steps {
script {
RELEASE = ""
if (env.TAG_NAME != null) {
RELEASE = env.TAG_NAME
} else {
RELEASE = env.BRANCH_NAME
}
env.RELEASE = "${RELEASE}"
echo "RELEASE=${RELEASE}"
}
}
}
stage('Build/Test') {
steps {
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
sh "mvn clean package --settings ./settings.xml"
}
}
}
stage('Release') {
when { tag "*" }
steps {
withCredentials([string(credentialsId: 'gitrelease', variable: 'TOKEN')]) {
withEnv(["TOKEN=$TOKEN"]) {
dir('target') {
sh script: '''
release=$(curl -XPOST -H "Authorization:token $TOKEN" --data "{\\"tag_name\\": \\"${RELEASE}\\", \\"target_commitish\\": \\"${BRANCH_NAME}\\", \\"name\\": \\"${RELEASE}\\", \\"body\\": \\"\\", \\"draft\\": false, \\"prerelease\\": false}" https://api.github.com/repos/metersphere/metersphere-plugin-DebugSampler/releases)
id=$(echo "$release" | sed -n -e \'s/"id":\\ \\([0-9]\\+\\),/\\1/p\' | head -n 1 | sed \'s/[[:blank:]]//g\')
curl -XPOST -H "Authorization:token $TOKEN" -H "Content-Type:application/octet-stream" --data-binary @metersphere-plugin-DebugSampler-${RELEASE}-jar-with-all-dependencies.jar https://uploads.github.com/repos/metersphere/metersphere-plugin-DebugSampler/releases/${id}/assets?name=metersphere-plugin-DebugSampler-${RELEASE}-jar-with-all-dependencies.jar
'''
}
}
}
}
}
stage('Upload') {
when { anyOf { tag pattern: "^\\d+\\.\\d+\\.\\d+\$", comparator: "REGEXP";tag pattern: "^\\d+\\.\\d+\\.\\d+-lts\$", comparator: "REGEXP"}}
steps {
dir('target') {
echo "UPLOADING"
withCredentials([usernamePassword(credentialsId: 'OSSKEY', passwordVariable: 'SK', usernameVariable: 'AK')]) {
sh("java -jar /opt/uploadToOss.jar $AK $SK fit2cloud2-offline-installer tools/metersphere/metersphere-plugin-DebugSampler-${RELEASE}-jar-with-all-dependencies.jar ./metersphere-plugin-DebugSampler-${RELEASE}-jar-with-all-dependencies.jar")
}
}
}
}
}
post('Notification') {
always {
withCredentials([string(credentialsId: 'wechat-bot-webhook', variable: 'WEBHOOK')]) {
qyWechatNotification failSend: true, mentionedId: '', mentionedMobile: '', webhookUrl: "$WEBHOOK"
}
}
}
}