You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DNS记录变更时触发Bitbucket Pipeline的解决方案及实现流程咨询

Hey there! Let me break down exactly how to set up an instant trigger for your Bitbucket Pipeline whenever your Azure DNS records change. This setup uses Azure's event-driven tools to connect the dots seamlessly. Here's your step-by-step guide:

Solution Overview

We'll leverage Azure Event Grid to monitor changes to your DNS zone, then use Azure Logic Apps (a low-code, easy-to-configure option) to forward those events to Bitbucket's Pipeline API, triggering your pipeline automatically.

1. Prerequisites

  • An active Azure subscription with permissions to manage DNS zones, Event Grid, and Logic Apps
  • A Bitbucket repository where you can configure pipelines and generate trigger tokens

2. Set Up Azure Event Grid Subscription to Monitor DNS Changes

First, we need to tell Azure to watch for DNS record updates or deletions:

  • Log into the Azure Portal, navigate to your DNS zone resource
  • Go to the Events tab in the left menu, then click + Event Subscription
  • Name your subscription something descriptive, like DNS-Changes-Bitbucket-Trigger
  • Under Event Types, check the boxes for Microsoft.Network.DNSZone.RecordSetUpdated and Microsoft.Network.DNSZone.RecordSetDeleted (pick whichever events you want to trigger on)
  • For Endpoint Type, select Logic App, then click Select an endpoint to either create a new Logic App or use an existing one (I recommend a new one for simplicity)

3. Configure Azure Logic App to Forward Events to Bitbucket

Now we'll build the Logic App workflow to send the trigger request to Bitbucket:

  • Open your newly created Logic App and go to the Designer
  • Use the When an Event Grid event is received trigger, and link it to the Event Grid subscription you just made
  • Add an HTTP action to the workflow, and configure these details:
    • Method: POST
    • URI: Bitbucket's pipeline trigger endpoint, formatted as https://api.bitbucket.org/2.0/repositories/{your-workspace}/{your-repo-name}/pipelines/
    • Headers:
      • Add Authorization with the value Bearer {your-bitbucket-trigger-token} (we'll generate this next)
      • Add Content-Type with the value application/json
    • Body: Use this JSON structure to trigger your desired pipeline (adjust the branch or custom target as needed):
      {
        "target": {
          "ref_type": "branch",
          "type": "pipeline_ref_target",
          "ref_name": "main" // Replace with your target branch name
        }
      }
      
  • Save the Logic App to activate the workflow

4. Generate a Bitbucket Pipeline Trigger Token

Bitbucket requires a token to authenticate API requests that trigger pipelines:

  • Log into Bitbucket, go to your repository, then click Settings in the left sidebar
  • Under Pipelines, select Trigger Tokens
  • Click Generate token, name it something like Azure-DNS-Event-Trigger, then click Create
  • Copy the generated token immediately (it won't be shown again!)

5. Customize Your Bitbucket Pipeline (Optional)

If you want to run specific actions when the DNS change triggers the pipeline, update your bitbucket-pipelines.yml file. For example:

pipelines:
  default:
    - step:
        name: Respond to DNS Change
        script:
          - echo "Detected a change to Azure DNS records!"
          # Add your custom commands here (e.g., sync configs, send alerts, run tests)
  # If you want a dedicated custom pipeline for DNS triggers
  custom:
    dns-trigger:
      - step:
          name: DNS Change Handler
          script:
            - echo "Running DNS-specific pipeline steps..."

If using a custom pipeline, update the Logic App's request body to target it:

{
  "target": {
    "type": "pipeline_custom_target",
    "selector": "dns-trigger"
  }
}

6. Test the Setup

  • Make a small change to your Azure DNS zone (e.g., edit an A record or add a CNAME)
  • Head over to your Bitbucket repository's Pipelines tab—you should see a new pipeline run start within a minute or two
  • Check your Logic App's Run History to confirm the HTTP request was sent successfully (if there's an error, double-check the token, URI, and request body)

Key Notes

  • Ensure your Logic App has outbound network access to Bitbucket's API (if using VNet-integrated Logic Apps, configure appropriate network rules)
  • Keep your Bitbucket trigger token secure—rotate it periodically and never commit it to code
  • You can add filters to your Event Grid subscription to only trigger on specific record types (e.g., A, CNAME) if you don't want every DNS change to start a pipeline
  • If you prefer code over low-code, you can replace Logic Apps with an Azure Function (write code in C#, Python, etc.) to handle the Event Grid event and call the Bitbucket API

内容的提问来源于stack exchange,提问作者Abhinav Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 22:04:05