Triggering Code Manager with a webhook

To deploy your code, you can trigger Code Manager by hitting a web endpoint, either through a webhook or a custom script. The webhook is the simplest way to trigger Code Manager.

Custom scripts are a good alternative if you have requirements such as existing continuous integration systems (including Continuous Delivery for Puppet Enterprise (PE)), privately hosted Git repos, or custom notifications. For information about writing a script to trigger Code Manager, see the related topic about creating custom scripts.

Code Manager supports webhooks for GitHub, Bitbucket Server (formerly Stash), Bitbucket, and Team Foundation Server. The webhook must only be used by the control repository. It can't be used by any other repository (for example, other internal component module repositories).
Important: Code Manager webhooks are not compatible with Continuous Delivery for PE. If your organization uses Continuous Delivery for PE, you must use a method other than webhooks to deploy environments.

Creating a Code Manager webhook

To set up the webhook to trigger environment deployments, you must create a custom URL, and then set up the webhook with your Git host.

Creating a custom URL for the Code Manager webhook

To trigger deployments with a webhook, you’ll need a custom URL to enable communication between your Git host and Code Manager.

Code Manager supports webhooks for GitHub, Bitbucket Server (formerly Stash), Bitbucket, GitLab (Push events only), and Team Foundation Server (TFS). To use the GitHub webhook with the Puppet signed cert, disable SSL verification.

To create the custom URL for your webhook, use the following elements:

  • Name: The name of the primary server (for example, code-manager.example.com).
  • Port: The Code Manager port (for example, 8170).
  • Endpoint: The endpoint (/code-manager/v1/webhook/).
  • Parameters: Any relevant query parameters (for example, type=github).
  • Authentication token: Your authentication token for deployments (token=<TOKEN>), passed with the token query parameter. To generate a token, see Request an authentication token for deployments.

For example, the URL for a GitHub webhook might look like this:

https://code-manager.example.com:8170/code-manager/v1/webhook?type=github&token=<TOKEN>

The URL for a version 5.4 or later Bitbucket Server webhook might look something like this:

 https://code-manager.example.com:8170/code-manager/v1/webhook?type=bitbucket-server&prefix=dev&token=<TOKEN>

With the complete token attached, a GitHub URL looks something like this:

https://code-manager.example.com:8170/code-manager/v1/webhook?type=github&token=0WJ4YPJVyQz26xm3X2I1Oihb7MUa68l2CZWjxM3vt4mQ

Code Manager webhook query parameters

The following query parameters are permitted in the Code Manager webhook.

The token query is mandatory, unless you disable authenticate_webhook in the Code Manager configuration.
  • type: Required. Specifies which type of post body to expect. Accepts:
    • github: GitHub
    • gitlab: GitLab
    • bitbucket-server: Bitbucket Server version 5.4 or later (formerly Stash)
    • bitbucket: Bitbucket
    • tfs-git: Team Foundation Server (resource version 1.0 is supported)
  • prefix: Specifies a prefix for converting branch names to environments.
    Important: You must provide the prefix parameter if the configuration of your control repository uses prefixing. If you do not specify this parameter, Code Manager cannot locate and deploy the correct environment or translate a branch name to the applicable environment name. See Configuring Sources in the related links for more information.
  • token: Specifies the entire PE authorization token.

Setting up the Code Manager webhook on your Git host

Enter the custom URL you created for Code Manager into your Git server’s webhook form as the payload URL.

The content type for webhooks is JSON.

Exactly how you set up your webhook varies, depending on where your Git repos are hosted. For example, in your GitHub repo, click on Settings > Webhooks & services to enter the payload URL and enter application/json as the content type.
Tip: On Bitbucket Server, the server configuration menu has settings for both "hooks" and "webhooks." To set up Code Manager, use the webhooks configuration. For proper webhook function with Bitbucket Server, make sure you are using the Bitbucket Server 5.4 or later and the latest fix version of PE.

After you've set up your webhook, your Code Manager setup is complete. When you commit new code and push it to your control repo, the webhook triggers Code Manager, and your code is deployed.

Testing and troubleshooting a Code Manager webhook

To test and troubleshoot your webhook, review your Git host logs or check the Code Manager troubleshooting guide.

Each of the major repository hosting services (such as GitHub or Bitbucket) provides a way to review the logs for your webhook runs, so check their documentation for instructions.

For other issues, check the Code Manager troubleshooting for some common problems and troubleshooting tips.