I'm trying to trigger a pipeline after a code push.
I follow this guidline : servicehook+webhook+pipeline
My topic is slighty different as it's not on pull request completion but logic is the same.
My issue is I didn't manage to retrieve webhook information. I tried different syntax. Always empty values.
Here is job runtime parameters:
Pipeline:
trigger: none
resources:
webhooks:
- webhook: MyWebHook
connection: MyServiceConnection
variables:
system.debug: true
subscriptionId: ${{ parameters.MyWebHook.resource.subscriptionId }}
notificationId: ${{ parameters.MyWebHook.resource.notificationId }}
eventType: ${{ parameters.MyWebHook.resource.eventType }}
message: ${{ parameters.MyWebHook.resource.message }}
messageText: ${{ parameters.MyWebHook.resource.message.text }}
commitId: ${{ parameters.CompletePR.resource.lastMergeCommit.commitId }}
commitComment: ${{ parameters.CompletePR.resource.lastMergeCommit.comment }}
pool:
vmImage: windows-latest
steps:
- checkout: none
- bash: |
echo "subscriptionId = $(subscriptionId)"
echo "notificationId = $(notificationId)"
echo "eventType = $(eventType)"
echo "notificationId = $(notificationId)"
echo "message = $(message)"
echo "messageText = $(messageText)"
echo "commitId = $(commitId)"
echo "commitComment = $(commitComment)"
displayName: 'Trigger Information'
It refused to trigger the pipeline, even if service hook has been fired. After many different tests, I noticed some property cancel pipeline trigger.
If I let the first three variables, it trigger the pipeline but with empty values :
Did I missed something ?
Thanks
As per the Webhooks resource definition:
You can consume the JSON payload data in your jobs as variables by using the format
${{ parameters.<WebhookAlias>.<JSONPath>}}
.
Considering the following payload:
{
"subscriptionId": "XXXXXXX",
"notificationId": "XX",
"eventType": "git.push",
"message": {
"text": "foobar"
}
# ...
}
You should set your variables like this:
resources:
webhooks:
- webhook: MyWebHook
connection: MyServiceConnection
variables:
subscriptionId: ${{ parameters.MyWebHook.subscriptionId }}
notificationId: ${{ parameters.MyWebHook.notificationId }}
eventType: ${{ parameters.MyWebHook.eventType }}
text: ${{ parameters.MyWebHook.message.text }}
# ...