-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathJenkinsfile
More file actions
51 lines (47 loc) · 1.94 KB
/
Jenkinsfile
File metadata and controls
51 lines (47 loc) · 1.94 KB
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
pipeline {
agent any
stages {
stage('Pull Request Events Only') {
when {
expression {
def action = (env.GITHUB_PR_ACTION ?: '').toLowerCase()
def eventName = (env.GITHUB_EVENT_NAME ?: '').toLowerCase()
def isPrCreateOrUpdate = ['opened', 'synchronize'].contains(action)
def isCommentEvent = ['created', 'commented'].contains(action) && [
env.GITHUB_COMMENT,
env.GITHUB_COMMENT_BODY,
env.GITHUB_PR_COMMENT
].any { it?.trim() }
// Support explicit GitHub event names for comment webhooks as well.
if (['issue_comment', 'pull_request_review', 'pull_request_review_comment'].contains(eventName)) {
isCommentEvent = true
}
return env.GITHUB_PR_NUMBER?.trim() && (isPrCreateOrUpdate || isCommentEvent)
}
}
stages {
stage('Generate GitHub Bot Properties') {
steps {
sh '''#!/bin/bash -x
env
echo "FORCE_PULL_REQUEST=$CHANGE_ID" > github-bot-properties
REPO_SHORT=$(echo $CHANGE_URL | sed -E 's|^[^/]+//[^/]+/([^/]*/[^/]*)/.*$|\1|')
echo "REPOSITORY=$REPO_SHORT" >> github-bot-properties
'''
}
}
stage('Trigger GitHub Bot Job') {
steps {
script {
def props = readProperties file: 'github-bot-properties'
def params = props.collect { k, v ->
string(name: k.toString(), value: v.toString())
}
build job: 'github-bot', parameters: params
}
}
}
}
}
}
}