Last week I had a quick message exchangement with a partner asking how to automatically trigger an Azure DevOps pipeline when a Dynamics 365 Business Central environment update occurs:
I’ve promised a post describing a possible idea for a solution, and here it is.
Triggering a build pipeline in Azure Devops when an update happens in a given Dynamics 365 Business Central environment is not a common type of pipeline trigger (usually in DevOps pipelines are triggered when a pull request occurs in a given branch, but that was the request) and this involves checking if a SaaS tenant has received a successfull update.
To create such workflow, you can use Azure Logic Apps. An Azure Logic App has two connectors that can help you on that:
With the Azure Application Insights connector, you can perform a KQL query in order to discover if (in a given period pof time) an environment upgrade is successfully performed.
With the Azure DevOps connector, you have a built-in connector to perform actions in a given Azure DevOps instance and also for triggering a build pipeline.
In this sample, I’ve used a timer-triggered workflow that runs every day:
Then I’m using the Azure Application Insights connector, and more specifically the Run Analytics Query action, to perform a KQL query in my Azure Application Insights instance (connected to my Dynamics 365 Business Central tenant):
The KQL query is the following:
traces
| where timestamp > ago(1d)
| where customDimensions.eventId == 'LC0106'
| where customDimensions.environmentName == 'Production'
| count
This KQL query gives you the number of successfully executed tenant upgrades for the current day (and for the given environment).
Then I can simply test if the Count value returned by this action is greater than 0:
If the Count value is greater than 0 for the current day, it means that a Dynamics 365 Business Central environment upgrade is executed successfully and so the Azure DevOps pipeline must be triggered.
To trigger an Azure DevOps build pipeline, we can use the Azure DevOps connector’s Queue a new build action:
The Queue a new build action also supports passing parameters to the pipeline. To pass parameters to a pipeline, you need to send a JSON dictionary with the values you want to use:
{
“parameter1”: “value1”,
“parameter2”: “value2”
}
and then from the pipeline you can read them with the $(keyName) syntax:
Pipelines parameters must be defined at the beginning of the YAML file and they need to have a default value, otherwise your pipeline fails.
In the pipeline’s code, parameters can be read by using the ${{ parameters.keyName}} syntax:
Just to provide an example, imagine that you need to retrieve the new updated version of your Dynamics 365 Business Central environment. You can do that from your Azure Logic Apps workflow by using the Run Analytics Query action with the following KQL query:
traces
| where timestamp > ago(1d)
| where customDimensions.eventId == 'LC0106'
| where customDimensions.environmentName == 'Production'
| project timestamp
, sourceVersion = customDimensions.sourceVersion
, destinationVersion = customDimensions.destinationVersion
| order by timestamp desc
| take int(1)
If you execute the above KQL query in Azure Application Insights, you can see that it gives you the following result (obviously, if you have a successfully executed tenant update ):
You can easily read the destinationVersion parameter in your workflow by taking the output of the Application Insights Run Analytics Query connector’s action :
and then pass it as a parameter to your Azure DevOps pipeline as previously described.
I hope that this post gives you an idea on how you can react to your Dynamics 365 Business Central environment lifecycle’s events and perform actions. Here the focus was to trigger an Azure DevOps pipeline when an update is succeeded, but you can do lots of other things in Azure DevOps (like for example opening a work item with the Create a work item action) and in all the other types of applications you want (Logic Apps is powerful). Just for reminder, these are the signals that gives you the lifecycle events for your Dynamics 365 Business Central environment: