Lukasz Skowroński - Senior Solutions Architect
31 Jan 2024
In the previous blog post we shared with you the process that helps with making your Sitecore’s CI/CD pipeline more bulletproof. In this blog post we will focus on the configuration that has to be applied to send webhook data from GitHub to Jenkins.
To configure webhooks you have to be an administrator and have access to the settings of repository and hooks section.
In the hooks section you have to press “Add webhook” button
It will open a form where you need to specify:
Url that has to be specified consists of:
and can look like this: http://jenkins.host/generic-webhook-trigger/invoke?token=xyz
The URL that we used in the previous step will be partially generated by the Jenkins plugin “Generic Webhook Trigger Plugin”. Thanks to this plugin in the build configuration you will see a new configuration option in the “Build Triggers” section where you will find information about the mentioned URL.
At the end of the URL configured on the GitHub side we had to add also token that is part of configuration of this plugin.
The most important task of this plugin is conversion of the received via webhook data into the object that you can use in your scripts. We must pay a lot attention to the notation at this point.
When GitHub sends data to Jenkins, it sends JSON object. When Jenkins receives that JSON object, it converts it to array of objects what is not well documented and may take some of your time to realize that. Based on the data being sent from GitHub you would expect expression like “$.payload” – but that would not work.
In the “Post content parameters” you have to configure payload variable as follows:
The next step that would make sense is to use payload variable in your scripts. Start with adding build step called “PowerShell” and then inside of it you can access variable by: $ENV:payload
Because we want to use with the Objects we have to convert Json to Object understandable by PowerShell scripts and we can make it by running a command: $payload = ConvertFrom-Json $ENV:payload
Starting from now you can use all of the properties that this object has like:
With having all that data available in your PowerShell scripts you can build many very useful processes.
I have been awarded with the Sitecore MVP award seven times (the first time in 2017) for my continued support of the Sitecore Community. Besides blogging, as a Sitecore Community member, I organize all of the Sitecore User Group meetups in Poland. Since 2021 I have helped to organize the Sitecore User Group Conference (SUGCON) as one of the co-organizers.
Share on social media