-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathJenkinsfile-k8s-jsonEvent-sub
63 lines (58 loc) · 2.47 KB
/
Jenkinsfile-k8s-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@Library("shared-starter") _
def event = ''
def myCoolKey = ''
pipeline {
agent none
triggers {
eventTrigger jmespathQuery("event=='helloWorld'")
}
stages {
stage('Example') {
agent {
kubernetes {
label 'sub'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.6.3-jdk-8
command:
- cat
tty: true
""" }
}
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()
firstName = currentBuild.getBuildCauses()[0]?.event?.firstName?.toString()
lastName = currentBuild.getBuildCauses()[0]?.event?.lastName?.toString()
}
echo "****************************************"
echo "extracted value for event: " + getEventValue(key:"event")
echo "extracted value for firstName: " + getEventValue(key:"firstName")
echo "extracted value for lastName: " + getEventValue(key:"lastName")
echo "****************************************"
}
}
}
}