forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
142 lines (123 loc) · 4.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import groovy.json.JsonSlurper
pipeline {
agent {
node {
label 'ubuntu'
}
}
options {
buildDiscarder(logRotator(daysToKeepStr: '14', artifactNumToKeepStr: '10'))
}
environment {
JAVA_HOME = "${tool 'jdk_1.8_latest'}"
}
tools {
maven 'maven_3_latest'
jdk 'jdk_1.8_latest'
}
triggers {
cron '''TZ=Asia/Shanghai
H 2,14 * * *'''
pollSCM '''TZ=Asia/Shanghai
H H/2 * * *'''
}
stages {
stage('Clone') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', noTags: true, reference: '', shallow: true]], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/apache/dubbo.git']]])
}
}
stage('Duplicate deploy check') {
steps {
script {
def deployedCommitId = sh(returnStdout: true, script: "curl --silent https://ci-builds.apache.org/job/Dubbo/job/${env.JOB_BASE_NAME}/lastSuccessfulBuild/artifact/DEPLOY_COMMIT_ID || true").trim()
env.DEPLOYED_COMMIT_ID = deployedCommitId
def commitId = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
env.COMMIT_ID = commitId
if (commitId == deployedCommitId) {
env.STATUS_CHECK = "false"
println "Latest deployed commit id is $deployedCommitId, Skip deployment this time"
} else {
env.STATUS_CHECK = "true"
println "Current commit id hasn't been deployed, continue"
}
}
}
}
stage('Commit status check') {
when {
expression {
return env.STATUS_CHECK == "true";
}
}
steps {
script {
def commitId = env.COMMIT_ID
println "Current commit id: $commitId"
def commitStatusJson = sh(script: "curl --silent https://api.github.com/repos/apache/dubbo/actions/runs", returnStdout: true).trim()
def jsonSlurper = new JsonSlurper()
def jsonObject = jsonSlurper.parseText(commitStatusJson)
def runs = jsonObject.workflow_runs
for (def run in runs) {
if (run.workflow_id == 5030221 && run.head_sha == commitId &&
run.event == "push" && run.head_branch == "master") {
println "Find github action for current commit: $run"
if (run.status == "completed" && run.conclusion == "success") {
env.STATUS_CHECK = "true"
println "CI status is success for commitId:$commitId, continue to deploy"
} else {
env.STATUS_CHECK = "false"
println "CI status is not success for commitId:$commitId"
}
break;
}
}
}
}
}
stage('Snapshot version check') {
when {
expression {
return env.STATUS_CHECK == "true";
}
}
steps {
sh 'env'
sh 'java -version'
sh './mvnw clean install -pl "dubbo-dependencies-bom" && ./mvnw clean install -DskipTests=true && ./mvnw clean validate -Psnapshot-ci-deploy -pl "dubbo-all"'
}
}
stage('Deploy snapshot') {
when {
expression {
return env.STATUS_CHECK == "true";
}
}
steps {
timeout(40) {
sh './mvnw --version'
sh './mvnw clean package deploy -pl dubbo-dependencies-bom && ./mvnw clean source:jar javadoc:jar package deploy -DskipTests=true'
}
}
}
stage('Save deployed commit id') {
steps {
script {
if (env.STATUS_CHECK != "true") {
println "Not pass status check"
env.COMMIT_ID = env.DEPLOYED_COMMIT_ID
}
}
writeFile file: 'DEPLOY_COMMIT_ID', text: "${env.COMMIT_ID}"
archiveArtifacts 'DEPLOY_COMMIT_ID'
}
}
}
post {
failure {
mail bcc: '', body: '''Project: ${env.JOB_NAME}
Build Number: ${env.BUILD_NUMBER}
URL: ${env.BUILD_URL}''', cc: '', from: '', replyTo: '', subject: 'Apache Dubbo snapshot deployment fail', to: '[email protected]'
}
}
}