Synapse CICD – Manage Triggers

Manage the Synapse pipeline triggers as part of your CICD DevOps process.

Context

I use an Azure Automation account to host my PowerShell script because it provides reusability and management of required modules. Schedules and logging are included but most importantly, it provides a REST API webhook that I can call from pipelines if necessary.

If you rather not use the Automation Account to run PowerShell, then you can still call the Synapse data-plane REST APIs directly as we have several operations for Triggers.

Trigger – REST API (Azure Synapse) | Microsoft Docs

Steps

  1. Create PowerShell run book in Azure Automation Account (requires modules Az.Accounts and Az.Synapse). Replace Tenant, App ID and Thumbprint values for your RunAs account.
param(
    $ws = "wplushiramsynapse",  #wplushiramsynapse (dev), hfpocws1 (prod)
    $ts = "Daily,Hourly,Last Day of Month", #list of triggers
    $status = "Start" #Start, Stop
)

# login
$null = Connect-AzAccount -ServicePrincipal `
    -Tenant 'aaaaaa' `
    -ApplicationId 'bbbbbb' `
    -CertificateThumbprint 'cccccc'

# enable
if ($status -eq "Start"){
    
    $triggers = $ts.split(",");

    foreach ($t in $triggers) {
        $t
        $trigger = Get-AzSynapseTrigger -WorkspaceName $ws -Name $t
        $trigger | Start-AzSynapseTrigger
    }
}

# disable
if ($status -eq "Stop"){
    
    $triggers = $ts.split(",");

    foreach ($t in $triggers) {
        $t
        $trigger = Get-AzSynapseTrigger -WorkspaceName $ws -Name $t
        $trigger | Stop-AzSynapseTrigger
    }
}
  1. Add a Webhook for your runbook using the default parameters and copy the URL. (Save it somewhere so we can use it step 6).
  1. Grant the RunAs of the Azure Automation Account resource Synapse Admin access to the target workspaces
  1. Edit the release and Install the Rest Call task. (Org admin will need to approve/add it)
  1. Refresh the Add tasks after its installed and Add the Rest Call task to your ADO release pipeline. Click Manage to create the WebService endpoint. (may need Org admin to add it)
  1. Choose Generic service, paste the Webhook URL, auth is not required, provide a name, grant access to all pipelines and Save.
  1. Return to the Release pipeline Rest Call task and refresh Web Service endpoint drop down. Select the service, choose Post method, you may provide a body for your POST request like in the example in step 5. Save and create a release to test.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.