-
Notifications
You must be signed in to change notification settings - Fork 76
/
Jenkinsfile-jsonEvent-sub
46 lines (41 loc) · 2 KB
/
Jenkinsfile-jsonEvent-sub
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
def event = ''
def myCoolKey = ''
pipeline {
agent none
triggers {
eventTrigger jmespathQuery("event=='helloWorld1' || event=='helloWorld2'")
}
stages {
stage('Example') {
agent any
when {
triggeredBy "EventTriggerCause"
beforeAgent true
}
steps {
echo "****************************************"
echo "The class type that triggered this run: " + currentBuild?.getBuildCauses()[0]?._class?.toString()
echo "****************************************"
echo "****************************************"
echo "The full message received:"
echo groovy.json.JsonOutput.prettyPrint(currentBuild?.getBuildCauses()?.toString())
echo "****************************************"
echo "****************************************"
echo "Just the event part of the full message received (note the new source value added on from the JSON from publishEvent):"
echo groovy.json.JsonOutput.prettyPrint(currentBuild?.getBuildCauses()[0]?.event?.toString())
echo "****************************************"
echo "****************************************"
echo "The value of event from the publishEvent JSON: " + currentBuild?.getBuildCauses()[0]?.event?.event?.toString()
echo "****************************************"
script {
event = currentBuild.getBuildCauses()[0]?.event?.event?.toString()
myCoolKey = currentBuild.getBuildCauses()[0]?.event?.myCoolKey?.toString()
}
echo "****************************************"
echo "extracted value for event: " + event
echo "extracted value for myCoolKey: " + myCoolKey
echo "****************************************"
}
}
}
}