I'm using the generic webhook trigger in Jenkins to respond handle bitbucket PR events.
Here is an example json that is being sent from the webhook
{
"eventKey":"pr:opened",
"date":"2017-09-19T09:58:11+1000",
"actor":{
"name":"admin",
"emailAddress":"[email protected]",
"id":1,
"displayName":"Administrator",
"active":true,
"slug":"admin",
"type":"NORMAL"
},
"pullRequest":{
"id":1,
"version":0,
"title":"a new file added",
"state":"OPEN",
"open":true,
"closed":false,
"createdDate":1505779091796,
"updatedDate":1505779091796,
"fromRef":{
"id":"refs/heads/a-branch",
"displayId":"a-branch",
"latestCommit":"ef8755f06ee4b28c96a847a95cb8ec8ed6ddd1ca",
"repository":{
"slug":"repository",
"id":84,
"name":"repository",
"scmId":"git",
"state":"AVAILABLE",
"statusMessage":"Available",
"forkable":true,
"project":{
"key":"PROJ",
"id":84,
"name":"project",
"public":false,
"type":"NORMAL"
},
"links": {
"clone": [
{
"href": "ssh://myrepo.git",
"name": "ssh"
},
{
"href": "https://myrepo.git",
"name": "http"
}
],
"self": [
{
"href": "https://myrepo/browse"
}
]
},
"public":false
}
},
"toRef":{
"id":"refs/heads/master",
"displayId":"master",
"latestCommit":"178864a7d521b6f5e720b386b2c2b0ef8563e0dc",
"repository":{
"slug":"repository",
"id":84,
"name":"repository",
"scmId":"git",
"state":"AVAILABLE",
"statusMessage":"Available",
"forkable":true,
"project":{
"key":"PROJ",
"id":84,
"name":"project",
"public":false,
"type":"NORMAL"
},
"public":false
}
},
"locked":false,
"author":{
"user":{
"name":"admin",
"emailAddress":"[email protected]",
"id":1,
"displayName":"Administrator",
"active":true,
"slug":"admin",
"type":"NORMAL"
},
"role":"AUTHOR",
"approved":false,
"status":"UNAPPROVED"
},
"reviewers":[
],
"participants":[
],
"links":{
"self":[
null
]
}
}
}
Just to start, I know the JSONPaths always return a list. This question is about a difference in behavior (it seems) in the Jenkins plugin when I using filter expressions.
So here are some JSONPath queries I use.
$.pullRequest.fromRef.latestCommit
If I stick that in https://jsonpath.curiousconcept.com I get what you'd expect a list with 1 item
[
"ef8755f06ee4b28c96a847a95cb8ec8ed6ddd1ca"
]
This comes through in my Jenkins job as ef8755f06ee4b28c96a847a95cb8ec8ed6ddd1ca
which is what I want.
I also want to retrieve the https repository clone link from the 'fromRef'
the JsonPath for that looks like this
$.pullRequest.fromRef.repository.links.clone[?(@.name=='http')].href
If I stick that in https://jsonpath.curiousconcept.com
I get the expected result
[
"https://myrepo.git"
]
However in Jenkins this comes through as ["https://myrepo.git"]
I can't figure out why it seems to still handle that as a list.
I've tried adding indexers like [0] after the query (...[?(@.name=='http')][0]) or after the property accessor (...[?(@.name=='http')].href[0]) or using [*]
none of which work - they result in an empty string in both the JSON Path tester and Jenkins.
I'm hoping someone can point out where I'm going wrong or give me some kind of work around?