-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathJenkinsfile
54 lines (54 loc) · 2.29 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
pipeline {
agent {
node {
label 'master'
}
}
options { quietPeriod(2400) }
environment {
JAVA_HOME = '/opt/jdk-11'
}
stages {
stage('Build/Test') {
steps {
configFileProvider([configFile(fileId: 'metersphere-maven', targetLocation: 'settings.xml')]) {
sh """#!/bin/bash -e
export JAVA_HOME=/opt/jdk-11
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH
java -version
./mvnw clean package --settings ./settings.xml
"""
}
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'target/*.hpi', followSymlinks: false
}
}
stage('Release') {
when { tag pattern: "^v.*", comparator: "REGEXP" }
steps {
withCredentials([string(credentialsId: 'gitrelease', variable: 'TOKEN')]) {
withEnv(["TOKEN=$TOKEN"]) {
sh script: '''
release=$(curl -XPOST -H "Authorization:token $TOKEN" --data "{\\"tag_name\\": \\"${TAG_NAME}\\", \\"name\\": \\"${TAG_NAME}\\", \\"body\\": \\"\\", \\"draft\\": false, \\"prerelease\\": true}" https://api.github.com/repos/metersphere/jenkins-plugin/releases)
id=$(echo "$release" | sed -n -e \'s/"id":\\ \\([0-9]\\+\\),/\\1/p\' | head -n 1 | sed \'s/[[:blank:]]//g\')
cd target
curl -XPOST -H "Authorization:token $TOKEN" -H "Content-Type:application/octet-stream" --data-binary @metersphere-v3-jenkins-plugin.hpi https://uploads.github.com/repos/metersphere/jenkins-plugin/releases/${id}/assets?name=metersphere-jenkins-plugin-${TAG_NAME}.hpi
'''
}
}
}
}
}
post('Notification') {
always {
sh "echo \$WEBHOOK\n"
withCredentials([string(credentialsId: 'wechat-bot-webhook', variable: 'WEBHOOK')]) {
qyWechatNotification failNotify: true, mentionedId: '', mentionedMobile: '', webhookUrl: "$WEBHOOK"
}
}
}
}