-
Notifications
You must be signed in to change notification settings - Fork 152
/
jenkinsfile-types-of-build-cause
49 lines (33 loc) · 1.47 KB
/
jenkinsfile-types-of-build-cause
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
// Orig Ref From :: https://github.com/benwtr/jenkins_experiment/blob/master/Jenkinsfile
properties [
[
$class: 'ParametersDefinitionProperty', parameterDefinitions: [
[
$class: 'ChoiceParameterDefinition', choices: ['plan', 'apply'], description: 'When this job is invoked directly, action that TF will perform', name: 'tf_action'
],
[
$class: 'GitParameterDefinition', branch: '', branchFilter: '.*', defaultValue: 'master', description: 'Branch to use for plan when this job is invoked directly. This is ignored and always "master" when tf_action is apply', name: 'git_branch', quickFilterEnabled: true, sortMode: 'ASCENDING_SMART', tagFilter: '*', type: 'PT_BRANCH'
]
]
]
]
// https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/get-build-cause/getBuildCause.groovy
def causes = currentBuild.rawBuild.getCauses()
println causes.dump()
println causes
causes = ''
PRCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.github.pullrequest.GitHubPRCause)
SCMCause = currentBuild.rawBuild.getCause(hudson.triggers.SCMTrigger$SCMTriggerCause)
UserCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
if (PRCause) {
println PRCause.properties
} else if (SCMCause) {
println SCMCause.properties
} else if (UserCause) {
println UserCause.properties
} else {
error 'This job cant be triggered however it was just triggered, sorry.'
}
PRCause = null
SCMCause = null
UserCause = null