Dans l'interface Web Secure Source Manager, accédez au dépôt pour lequel vous souhaitez créer un webhook.
Cliquez sur Paramètres.
Cliquez sur Webhooks, puis sur Add webhook (Ajouter un Webhook).
Dans le champ ID du hook, saisissez un ID pour le webhook.
Dans le champ URL cible, saisissez l'URL du webhook. Par exemple, si vous souhaitez déclencher une compilation dans Jenkins, vous pouvez configurer un déclencheur de webhook, puis saisir l'URL du déclencheur Jenkins ici pour déclencher votre compilation dans Jenkins.
Si l'URL de rappel contient les valeurs de clé et de code secret que vous avez saisies lorsque vous avez créé votre déclencheur de webhook, supprimez-les de la fin de l'URL cible et copiez-les dans le champ Chaîne de requête sensible.
Pour trouver votre clé et votre secret dans l'URL du webhook, recherchez le texte commençant par key=.
Par exemple, pour l'URL suivante :
https://cloudbuild.googleapis.com/v1/projects/my-project/triggers/test-trigger:webhook?key=eitIfKhYnv0LrkdsyHqIros8fbsheKRIslfsdngf&secret=Hello%20Secret%20Manager
Copiez et supprimez la partie commençant par le point d'interrogation
?key=... dans le champ URL cible. Supprimez ensuite le point d'interrogation initial et déplacez la partie restante key=... dans le champ Chaîne de requête sensible.
Dans la section Déclencher sur, sélectionnez l'une des options suivantes :
Push : pour déclencher une action lors d'un transfert push vers le dépôt.
État de la demande d'extraction modifié : pour déclencher un événement lorsque l'état de la demande d'extraction change.
Si vous avez sélectionné Déployer, vous pouvez saisir une liste d'autorisation pour les événements de déploiement dans le champ Filtre de branche.
Le champ Filtre de branche utilise le modèle glob. Seules les opérations sur les branches correspondantes déclenchent une déclencheur de compilation. Si le champ est vide ou défini sur *, les événements push pour toutes les branches sont signalés. Pour en savoir plus sur la syntaxe, consultez la documentation glob.
Cliquez sur Add webhook (Ajouter un Webhook).
Le webhook s'affiche sur la page Webhooks.
Tester votre webhook
Sur la page Webhooks de Secure Source Manager, cliquez sur le webhook que vous souhaitez tester.
En bas de la page, cliquez sur Test delivery (Distribution des tests).
Un événement espace réservé est ajouté à la file d'attente de diffusion. Il peut s'écouler quelques secondes avant qu'il n'apparaisse dans l'historique des livraisons.
Vous pouvez également utiliser une commande git pour envoyer ou fusionner une demande d'extraction;extraction afin de tester le webhook.
Vérifiez l'état de la compilation ou de l'événement déclenchés dans l'historique des compilations du service dans lequel vous avez configuré votre déclencheur de webhook.
Vous pouvez également afficher la demande et la réponse à la diffusion du test dans la section Diffusions récentes de la page du webhook Secure Source Manager après avoir envoyé votre première diffusion de test.
Substituer les variables YAML Cloud Build par des données de charge utile
Si vous utilisez des webhooks pour vous connecter à Cloud Build, vous pouvez remplacer les variables YAML Cloud Build par des données de charge utile de webhook Secure Source Manager.
Sur la page Webhooks de Secure Source Manager, dans la section Livraisons récentes, cliquez sur la première ligne.
L'en-tête et le contenu de la requête envoyés par la charge utile du webhook s'affichent.
Accédez au tableau de bord Cloud Build, puis cliquez sur Déclencheurs.
Cliquez sur le déclencheur que vous souhaitez configurer.
Dans la section Avancé, sous Variables de substitution, cliquez sur + Ajouter une variable.
Saisissez le nom et la valeur de la variable. Le préfixe de la valeur est body.
Par exemple, pour remplacer _REPO_URL par le champ de données de charge utile repository.clone_url et _COMMIT_SHA par le dernier commit sha dans le fichier YAML Cloud Build, saisissez les noms et valeurs suivants :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Set up webhooks\n\nThis page describes how to set up webhooks in Secure Source Manager.\n\nWebhooks are HTTP requests triggered by an event in Secure Source Manager, and\nsent to a user-specified URL.\n\nBefore you begin\n----------------\n\n1. [Create a Secure Source Manager instance](/secure-source-manager/docs/create-instance).\n2. [Create a Secure Source Manager repository](/secure-source-manager/docs/create-repository).\n\n### Required roles\n\n\nTo get the permissions that\nyou need to create webhooks,\n\nask your administrator to grant you the\nfollowing IAM roles:\n\n- [Secure Source Manager Repository Admin](/iam/docs/roles-permissions/securesourcemanager#securesourcemanager.repoAdmin) (`roles/securesourcemanager.repoAdmin`) on the Secure Source Manager repository\n- [Secure Source Manager Instance Accessor](/iam/docs/roles-permissions/securesourcemanager#securesourcemanager.instanceAccessor) (`roles/securesourcemanager.instanceAccessor`) on the Secure Source Manager instance\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nFor information on granting Secure Source Manager roles,\nsee [Access control with IAM](/secure-source-manager/docs/access-control) and\n[Grant users instance access](/secure-source-manager/docs/grant-users-instance-access).\n\nSet up a webhook\n----------------\n\n1. In the Secure Source Manager web interface, navigate to the repository you want to create a webhook for.\n2. Click **Settings**.\n3. Click **Webhooks** , and then click **Add webhook**.\n4. In the **Hook ID** field, enter an ID for the webhook.\n\n | **Note:** Hook IDs must follow the [resource naming convention](https://google.aip.dev/122#resource-id-segments). They must include only lower case letters, numbers, or dashes, must begin with a letter, and cannot be changed after creating the webhook.\n5. In the **Target URL** field, enter the Webhook URL. For example, if you want\n to trigger a build in Jenkins, you could\n [Set up a webhook trigger](/secure-source-manager/docs/connect-jenkins#set_up_a_webhook_trigger), and then enter\n the Jenkins trigger URL here to trigger your build in Jenkins.\n\n6. If the Webhook URL contains your key and secret values entered when you\n created your webhook trigger, remove them from the end of the target URL\n and copy them to the **Sensitive Query String** field.\n\n To locate your key and secret in your webhook URL, look for the text\n starting with `key=`\n\n For example, given the following URL:\n `https://cloudbuild.googleapis.com/v1/projects/my-project/triggers/test-trigger:webhook?key=eitIfKhYnv0LrkdsyHqIros8fbsheKRIslfsdngf&secret=Hello%20Secret%20Manager`\n\n Copy and remove the portion starting with the question mark\n `?key=...` from the **Target URL** field. Then remove the initial question\n mark, move the remaining portion `key=...` to the **Sensitive Query String**\n field.\n7. In the **Trigger on** section, select one of the following:\n\n - **Push**: to trigger on a push to the repository.\n - **Pull request state changed**: to trigger on a change in the pull request state.\n8. If you selected **Push** , then you can enter an allowlist for push events in\n the **Branch filter** field.\n\n The **Branch filter** field uses the glob pattern and only operations on the\n matched branches will cause a build trigger. If the field is empty or `*`,\n then push events for all branches are reported. For information on syntax,\n see the [glob](https://pkg.go.dev/github.com/gobwas/glob) documentation.\n9. Click **Add webhook**.\n\n10. The webhook is displayed in the **Webhooks** page.\n\n | **Note:** When you add or edit a webhook, the length of the `Sensitive Query String` might be inconsistent with the entered one, which is expected as placeholder strings are used to ensure security.\n\nTest your webhook\n-----------------\n\n1. In the Secure Source Manager **Webhooks** page, click the webhook you want to test.\n2. Go to the bottom of the page and click **Test delivery**.\n\n A placeholder event is added to the delivery queue. It might take a few\n seconds before it shows up in the delivery history.\n3. You can also use a `git` command to push or merge a pull request to test the\n webhook.\n\n4. Check the status of the triggered build or event in the build history of the\n service where you configured your webhook trigger.\n\n5. You can also view the **Request** and **Response** to the test delivery\n in the **Recent deliveries** section of the Secure Source Manager\n webhook page after you send your first test delivery.\n\nSubstitute Cloud Build YAML variables with payload data\n-------------------------------------------------------\n\nIf you're using webhooks to connect to Cloud Build, you can substitute\nCloud Build YAML variables with Secure Source Manager webhook payload\ndata.\n\n1. In the Secure Source Manager **Webhooks** page, in the **Recent deliveries**\n section, click the top row.\n\n The **Request** header and content sent by the webhook payload is displayed.\n2. Navigate to the Cloud Build dashboard, and then click **Triggers**.\n\n3. Click the trigger you want to configure.\n\n4. In the **Advanced section** , under **Substitution variables** , click\n **+ Add variable**.\n\n5. Enter the name and value of the variable. The value prefix is `body`.\n\n For example, to substitute `_REPO_URL` with the payload data field\n `repository.clone_url` and `_COMMIT_SHA` with latest commit sha in\n Cloud Build YAML, enter the following names and values:\n - Variable 1: `_REPO_URL` Value 1: `$(body.repository.clone_url)`\n - Variable 2: `_COMMIT_SHA` Value 2: `$(body.after)`\n\n The Cloud Build YAML file resembles the following: \n\n steps:\n - name: gcr.io/cloud-builders/git\n env:\n - '_REPO_URL=$_REPO_URL'\n - '_COMMIT_SHA=$_COMMIT_SHA'\n script: |\n #!/bin/sh\n git clone ${_REPO_URL} /workspace\n cd /workspace\n git reset --hard ${_COMMIT_SHA}\n\nWhat's next\n-----------\n\n- [Connect to Jenkins](/secure-source-manager/docs/connect-jenkins)"]]