{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":21363,"path":"integrate-applications/integration-hub/receive-jenkins-upd.md","title":"Set up a webhook for the Jenkins spoke","bundle":null,"doc_type":null,"release":"australia","body":"\n# Set up a webhook for the Jenkins spoke\n\nSet up a webhook application to receive the required updates from Jenkins at your ServiceNow instance.\n\n## Before you begin\n\nRole required: admin\n\n## Create authorization key for the Jenkins v2 spoke\n\nCreate a authorization key to authorise requests from Jenkins.\n\n### Before you begin\n\nRole required: admin.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **System Definition** &gt; **Scripts - Background**.\n\n2.  Enter this command in the **Run script \\(JavaScript executed on server\\)** text field:\n\n    `gs.info(GlideSecureRandomUtil.getSecureRandomString(32));`\n\n3.  Click **Run Script**.\n\n4.  Copy and record the generated value for later use.\n\n    \\[Omitted image \"auth-token.png\"\\] Alt text: Client Secret or Authorization Key\n\n\n## Provide authorization key for webhook\n\nAuthorise requests from Jenkins by providing authorization key for webhook in your ServiceNow instance.\n\n### Before you begin\n\nRole required: admin\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Jenkins v2** &gt; **Webhook Client Details**.\n\n2.  Click **New**.\n\n3.  On the form, fill these values:\n\n    |Field|Description|\n    |-----|-----------|\n    |Authorization Key|Authorization key you had generated. See [Create authorization key for the Jenkins v2 spoke](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/integration-hub/receive-jenkins-upd.md) for more information.|\n    |Name|Name to identify the webhook client record.|\n\n4.  Click **Submit**.\n\n\n## Provide authorization key in Jenkins\n\nReceive updates from Jenkins by providing the authorization key in Jenkins.\n\n### Before you begin\n\nRole required: admin.\n\n### Procedure\n\n1.  Log in to your Jenkins account.\n\n2.  Click and open the job for which you want to configure your webhook.\n\n3.  Click **Configure**.\n\n4.  In the **Bindings** tab, click **Add** and select **Jenkins**.\n\n    For more information about the using the plugin, see [Credentials Binding](https://plugins.jenkins.io/credentials-binding/).\n\n    \\[Omitted image \"jenkins-bindings.png\"\\] Alt text: Jenkins Credentials Provider\n\n5.  On the form, fill in the fields.\n\n    |Field|Description|\n    |-----|-----------|\n    |Kind|Select **Secret text**.|\n    |Secret|Enter authorization key. See [Create authorization key for the Jenkins v2 spoke](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/integration-hub/receive-jenkins-upd.md) for more information.|\n    |ID|Provide unique identifier to identify the record.|\n\n6.  Click **Add**.\n\n7.  In the **Post-build Actions** tab, configure task and specify script to receive updates at your ServiceNow instance.\n\n    -   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%\\\"}\"`\n    -   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}\\\"}\"`\n    **Note:** ID in the script is the ID you had provided in the Jenkins Credential Provider form.\n\n    For more information about the using the plugin, see [Post build task](https://plugins.jenkins.io/postbuild-task/).\n\n8.  Click **Apply**.\n\n\n## Provide description to subflow\n\nProvide user friendly descriptions to the subflows in the Jenkins v2 spoke.\n\n### Before you begin\n\nRole required: admin.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Jenkins v2** &gt; **Webhook Answer Subflows**.\n\n2.  Click **New**.\n\n3.  On the form, fill these values:\n\n    |Field|Description|\n    |-----|-----------|\n    |Description|Description about the subflow.|\n    |Subflow|Required subflow in the Jenkins v2 spoke.|\n\n4.  Click **Submit**.\n\n\n## Provide answers to the decision table\n\nProvide subflows as answers to the conditions mentioned in the decision table. When the specified conditions are met, the associated subflow is triggered.\n\n### Before you begin\n\nRole required: admin\n\n### Procedure\n\n1.  Navigate to **All** &gt; **System Definition** &gt; **Decision Tables**.\n\n2.  Open the record for the **Jenkins v2 spoke**.\n\n3.  In the **Decisions** tab, click **New**.\n\n4.  On the form, fill these values:\n\n<table id=\"table_awj_xgv_z3b\"><thead><tr><th>\n\nField\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nLabel\n\n</td><td>\n\nUnique label to identify the routing policy.\n\n</td></tr><tr><td>\n\nDefault answer\n\n</td><td>\n\nOption to specify if this is the default answer. The default answer is applicable when the conditions are not met.\n\n</td></tr><tr><td>\n\nCondition\n\n</td><td>\n\nConditions to be met when the required events occur in Jenkins. See [Jenkins v2 Spoke](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/integration-hub/jenkins-spoke.md) for information about the supported fields.\n\n</td></tr><tr><td>\n\nAnswer\n\n</td><td>\n\nSubflow that must be triggered when the specified conditions are met.1.  Click the Lookup icon \\(\\[Omitted image \"lookup-icon.png\"\\] Alt text: Lookup icon\\).\n2.  Select the required subflow from the Document list.\n\n**Note:** Ensure that the **Table name** is `Jenkins v2 Webhook Answer Subflow [sn_jenkinsv2_spoke_webhook_answer_subflow]`.\n\n</td></tr></tbody>\n</table>5.  Click **Submit**.\n\n\n## Customize a webhook\n\nCreate a webhook routing policy and customize subflow as per your requirement.\n\n### Before you begin\n\nRole required: admin\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Flow Designer** &gt; **Designer**.\n\n2.  Click **Subflows**.\n\n3.  Create a copy of the required default subflow.\n\n4.  Customize the Jenkins Webhook Answer Subflow: Process build information subflow as per your requirement and publish it.\n\n    See [Building subflows](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/subflows.md) for more information about creating and using subflows and [Jenkins v2 Spoke](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/integration-hub/jenkins-spoke.md) for information about the fields that the routing policies and subflows support.\n\n5.  Navigate to **Jenkins v2** &gt; **WebHook Answer Subflows**.\n\n6.  Click **New**.\n\n7.  On the form, fill in the fields.\n\n    |Field|Description|\n    |-----|-----------|\n    |Description|Description about the subflow.|\n    |Subflow|Required subflow in the Jenkins v2 spoke.|\n\n8.  Click **Submit**.\n\n    **Note:** These routing policies are saved in the Decision tables. Users are cautioned against directly updating or modifying data in these tables.\n\n9.  Navigate to **System Definition** &gt; **Decision Tables**.\n\n10. Open the record for the **Jenkins v2** spoke.\n\n11. In the **Decisions** tab, click **New**.\n\n12. On the form, fill these fields:\n\n<table id=\"table_zhp_k2d_hlb\"><thead><tr><th>\n\nField\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nLabel\n\n</td><td>\n\nUnique label to identify the routing policy.\n\n</td></tr><tr><td>\n\nDefault answer\n\n</td><td>\n\nOption to specify if this is the default answer. The default answer is applicable when the conditions are not met.\n\n</td></tr><tr><td>\n\nCondition\n\n</td><td>\n\nConditions to be met when the required events occur in Jenkins. See [Jenkins v2 Spoke](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/integration-hub/jenkins-spoke.md) for information about the supported fields.\n\n</td></tr><tr><td>\n\nAnswer\n\n</td><td>\n\nSubflow that must be triggered when the specified conditions are met.1.  Click the Lookup icon \\(\\[Omitted image \"lookup-icon.png\"\\] Alt text: Lookup icon\\).\n2.  Select the required subflow from the Document list.\n\n**Note:** Ensure that the **Table name** is `Jenkins v2 Webhook Answer Subflow [sn_jenkinsv2_spoke_webhook_answer_subflow]`.\n\n</td></tr></tbody>\n</table>13. Click **Submit**.\n\n\n"}}