Set up a webhook for the Jenkins spoke
Set up a webhook application to receive the required updates from Jenkins at your ServiceNow instance.
Before you begin
Create authorization key for the Jenkins v2 spoke
Create a authorization key to authorise requests from Jenkins.
Before you begin
Role required: admin.
Procedure
- Navigate to All > System Definition > Scripts - Background.
-
Enter this command in the Run script (JavaScript executed on
server) text field:
gs.info(GlideSecureRandomUtil.getSecureRandomString(32)); - Click Run Script.
-
Copy and record the generated value for later use.
Provide authorization key for webhook
Authorise requests from Jenkins by providing authorization key for webhook in your ServiceNow instance.
Before you begin
Role required: admin
Procedure
- Navigate to All > Jenkins v2 > Webhook Client Details.
- Click New.
-
On the form, fill these values:
Table 1. Jenkins Webhook Client Details form Field Description Authorization Key Authorization key you had generated. See Create authorization key for the Jenkins v2 spoke for more information. Name Name to identify the webhook client record. - Click Submit.
Provide authorization key in Jenkins
Receive updates from Jenkins by providing the authorization key in Jenkins.
Before you begin
Role required: admin.
Procedure
- Log in to your Jenkins account.
- Click and open the job for which you want to configure your webhook.
- Click Configure.
-
In the Bindings tab, click Add and select Jenkins.
For more information about the using the plugin, see Credentials Binding.
-
On the form, fill in the fields.
Table 2. Jenkins Credential Provider form Field Description Kind Select Secret text. Secret Enter authorization key. See Create authorization key for the Jenkins v2 spoke for more information. ID Provide unique identifier to identify the record. - Click Add.
-
In the Post-build Actions tab, configure task and
specify script to receive updates at your ServiceNow
instance.
- Sample Windows
Script:
curl "https://<instance-name>.service-now.com/api/sn_jenkinsv2_spoke/jenkins_v2_webhook/build_status" -X POST -H "content-type:application/json" -H "jenkinsKey: %<ID>%" -d "{\"Job_Name\":\"%JOB_NAME%\",\"Job_Path\":\"%JOB_URL%\",\"Build_Number\":\"%BUILD_NUMBER%\"}" - Sample Shell Script:
curl "https://<instance-name>.service-now.com/api/sn_jenkinsv2_spoke/jenkins_v2_webhook/build_status" -X POST -H "content-type:application/json" -H "jenkinsKey: ${<ID>}" -d "{\"Job_Name\":\"${JOB_NAME}\",\"Job_Path\":\"${JOB_URL}\",\"Build_Number\":\"${BUILD_NUMBER}\"}"
Note:For more information about the using the plugin, see Post build task.ID in the script is the ID you had provided in the Jenkins Credential Provider form. - Sample Windows
Script:
- Click Apply.
Provide description to subflow
Provide user friendly descriptions to the subflows in the Jenkins v2 spoke.
Before you begin
Role required: admin.
Procedure
- Navigate to All > Jenkins v2 > Webhook Answer Subflows.
- Click New.
-
On the form, fill these values:
Field Description Description Description about the subflow. Subflow Required subflow in the Jenkins v2 spoke. - Click Submit.
Provide answers to the decision table
Provide subflows as answers to the conditions mentioned in the decision table. When the specified conditions are met, the associated subflow is triggered.
Before you begin
Role required: admin
Procedure
- Navigate to All > System Definition > Decision Tables.
- Open the record for the Jenkins v2 spoke.
- In the Decisions tab, click New.
-
On the form, fill these values:
Table 3. Decision form Field Description Label Unique label to identify the routing policy. Default answer Option to specify if this is the default answer. The default answer is applicable when the conditions are not met. Condition Conditions to be met when the required events occur in Jenkins. See Jenkins v2 Spoke for information about the supported fields. Answer Subflow that must be triggered when the specified conditions are met. - Click the Lookup icon (
).
- Select the required subflow from the Document
list.Note:Ensure that the Table name is Jenkins v2 Webhook Answer Subflow [sn_jenkinsv2_spoke_webhook_answer_subflow].
- Click the Lookup icon (
- Click Submit.
Customize a webhook
Create a webhook routing policy and customize subflow as per your requirement.
Before you begin
Role required: admin
Procedure
- Navigate to All > Flow Designer > Designer.
- Click Subflows.
- Create a copy of the required default subflow.
-
Customize the Jenkins Webhook Answer Subflow: Process build information subflow as per your requirement and publish it.
See Building subflows for more information about creating and using subflows and Jenkins v2 Spoke for information about the fields that the routing policies and subflows support.
- Navigate to Jenkins v2 > WebHook Answer Subflows.
- Click New.
-
On the form, fill in the fields.
Field Description Description Description about the subflow. Subflow Required subflow in the Jenkins v2 spoke. -
Click Submit.
Note:These routing policies are saved in the Decision tables. Users are cautioned against directly updating or modifying data in these tables.
- Navigate to System Definition > Decision Tables.
- Open the record for the Jenkins v2 spoke.
- In the Decisions tab, click New.
-
On the form, fill these fields:
Table 4. Decision form Field Description Label Unique label to identify the routing policy. Default answer Option to specify if this is the default answer. The default answer is applicable when the conditions are not met. Condition Conditions to be met when the required events occur in Jenkins. See Jenkins v2 Spoke for information about the supported fields. Answer Subflow that must be triggered when the specified conditions are met. - Click the Lookup icon (
).
- Select the required subflow from the Document
list.Note:Ensure that the Table name is Jenkins v2 Webhook Answer Subflow [sn_jenkinsv2_spoke_webhook_answer_subflow].
- Click the Lookup icon (
- Click Submit.