Webhooks configuration with codemagic.yaml

Set up webhooks for automatic builds

Webhooks are necessary in order to be able to trigger builds automatically in response to events in the repository.

The payload URL has the following format: https://api.codemagic.io/hooks/<appId>.

You can find your app ID in the browser URL after app/ when you open the app on Codemagic: https://codemagic.io/app/<appId>

All received webhooks are visible in the Codemagic UI when navigating to your application and selecting the Webhooks tab.

After configuring Webhooks, automatic build triggering can be set up as explained here. More information about how to set up automatic build triggering in the yaml file can be found here.

Setting up webhooks for Github

Open your project and navigate to Settings > Webhooks > Add webhook, paste the payload URL from above (both application/json or application/x-www-form-urlencoded are supported as the Content type), and select the following events: Branch or tag creation, Pull requests, Pushes.

Setting up webhooks for GitLab

Navigate to Settings > Webhooks, paste the payload URL and check the following boxes in the Trigger section: Push events, Tag push events, Merge request events. Also, be sure to enable SSL verification.

Setting up webhooks for Bitbucket

Open your application repository, go to Settings > Webhooks (in Workflow section) > Add webhook, then enter an arbitrary title for the webhook and paste the payload URL in the URL field. For Triggers, select Choose from a full list of triggers and select the following events: Push in the Repository section and Created, Updated, Merged in the Pull Request section.

Setting up webhooks for AWS CodeCommit

To start using webhooks with AWS CodeCommit, it is first necessary to create a subscription with the AWS Simple Notification Service.

Configuring the subscription

  1. Open up AWS Simple Notification Service in the AWS Console.
  2. Navigate to Topics > Create topic.
  3. Set the type to Standard, give the topic a name and click on Create topic.
  4. Navigate to Subscriptions > Create subscription.
  5. Select the previously configured topic, set the protocol to HTTPS, and set the Codemagic payload URL as the endpoint.
  6. Confirm that Enable raw message delivery is unticked.
  7. Proceed by clicking Create subscription.
  8. In the Codemagic UI, navigate to your application and select the Webhooks tab.
  9. Under Recent deliveries, choose the most recent webhook, and copy the subscription link under the Results tab to your browser.

Configuring webhook events

Open your application repository and navigate to Notify > Create notification rule and enter a name for your Notification rule.

Under Events that trigger notifications, select the Source updated and Created events in the Pull request section and the Created and Updated events in the Branches and tags section.

Set the target type to SNS topic, select a configured target and click on Submit.

If, after triggering a build, the SNS Notification target status shows as Unreachable, navigate to the topic settings and modify the access policy to match the following structure:

{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Sid": "CodeNotification_publish",
      "Effect": "Allow",
      "Principal": {
        "Service": "codestar-notifications.amazonaws.com"
      },
      "Action": "SNS:Publish",
      "Resource": "arn:aws:sns:REGION:ACCOUNT_ID:REPOSITORY"
    }
  ]
}

The Resource field should match the ARN of the topic.

Setting up webhooks for Azure DevOps

Open your application repository, go to Project Settings > Service Hooks, click on Create a new subscription… and select Web Hooks. Under Trigger on this type of event, choose the event you wish to trigger builds for. Codemagic supports Code pushed, Pull request created, and Pull request updated events. In Azure, each of the events requires its own webhook. Once the event has been selected, choose your repository under filters and configure any additional settings.