This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
forked from JavierCVilla/jenkins-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pullrequests.groovy
75 lines (60 loc) · 2.98 KB
/
Pullrequests.groovy
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
#!groovy
@Library('fcc-pipelines')
import cern.root.pipeline.*
properties([
parameters([
string(name: 'ghprbPullId', defaultValue: '61'),
string(name: 'ghprbGhRepository', defaultValue: ''),
string(name: 'ghprbCommentBody', defaultValue: '@phsft-bot build'),
string(name: 'ghprbTargetBranch', defaultValue: 'master'),
string(name: 'ghprbActualCommit', defaultValue: ''),
string(name: 'sha1', defaultValue: ''),
string(name: 'VERSION', defaultValue: 'master', description: 'Branch to be built'),
//string(name: 'EXTERNALS', defaultValue: 'ROOT-latest', description: ''),
//string(name: 'EMPTY_BINARY', defaultValue: 'true', description: 'Boolean to empty the binary directory (i.e. to force a full re-build)'),
string(name: 'ExtraCMakeOptions', defaultValue: '', description: 'Additional CMake configuration options of the form "-Doption1=value1 -Doption2=value2"'),
string(name: 'MODE', defaultValue: 'pullrequests', description: 'The build mode'),
string(name: 'PARENT', defaultValue: '', description: 'Trigger job name')
])
])
timestamps {
def packageName = params.ghprbGhRepository.tokenize('/').last().toLowerCase()
def buildJobName = packageName + "-pullrequests-build"
if(!params.PARENT){
params.PARENT = packageName.toUpperCase() + "-pullrequests-trigger"
}
GitHub gitHub = new GitHub(this, PARENT, ghprbGhRepository, ghprbPullId, params.ghprbActualCommit)
BotParser parser = new BotParser(this, params.ExtraCMakeOptions)
GenericBuild build = new GenericBuild(this, buildJobName, params.MODE)
build.addBuildParameter('PKG_NAME', "${packageName}")
build.addBuildParameter('PKG_REFSPEC', "+refs/pull/${ghprbPullId}/head:refs/remotes/origin/pr/${ghprbPullId}/head")
build.addBuildParameter('PKG_BRANCH', "origin/pr/${ghprbPullId}/head")
build.addBuildParameter('PKGTEST_BRANCH', "${params.ghprbTargetBranch}")
build.addBuildParameter('GIT_COMMIT', "${params.sha1}")
build.addBuildParameter('BUILD_NOTE', "PR #$ghprbPullId")
currentBuild.setDisplayName("#$BUILD_NUMBER PR #$ghprbPullId")
build.cancelBuilds('.*PR #' + ghprbPullId + '$')
build.afterBuild({buildWrapper ->
if (buildWrapper.result.result != 'SUCCESS' && currentBuild.result != 'ABORTED') {
gitHub.postResultComment(buildWrapper)
}
})
if (parser.isParsableComment(ghprbCommentBody.trim())) {
parser.parse()
}
parser.postStatusComment(gitHub)
parser.configure(build)
gitHub.setPendingCommitStatus('Building')
build.build()
stage('Publish reports') {
if (currentBuild.result == 'SUCCESS') {
gitHub.setSucceedCommitStatus('Build passed')
gitHub.postComment("All tests succeeded")
} else if (currentBuild.result != 'ABORTED') {
gitHub.setFailedCommitStatus('Build failed')
}
if (currentBuild.result != null) {
build.sendEmails()
}
}
}