We know that in Logic Apps there are loads of connectors to integrate with Azure DevOps to do things like automate builds and work items but what if you want to integrate the other way around?

I had a scenario where I want to call out to a Logic App from my Azure DevOps pipeline to upload a file to a document repository. I think this is a good example to show how you can combine DevOps pipelines and Logic Apps to extend your CICD processed to participate in wider integration scenarios.

Its actually really easy to do this scenario and you could also do a similar approach to trigger a Power Automate flow if you were using that rather than Logic Apps.

In this scenario I created a Logic App which would take an HTTP request message which included headers which told me the sharepoint site, library and target file name.

I then would use the body of the input message as the file content. The logic app looks like the below.

In my DevOps pipeline I can now use the Azure Powershell task to lookup the url for my logic app and then I can send a message to it in Powershell which will kick off my logic app which in this case will create the file in SharePoint.


Write-Host 'Starting upload to SharePoint via Logic App'
     
     Write-Host 'Retrieving Logic App Url'
     $resourceGroup = '[My_RG]'
     $logicAppName = '[My_LA]'
     $triggerName = 'manual'
     $logicAppCallbackUrl = Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName $resourceGroup -Name $logicAppName -TriggerName $triggerName
     $logicAppUrl = $logicAppCallbackUrl.Value
     
     $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
     $headers.Add("Document-Path", "[SharePoint-Folder]")
     $headers.Add("Document-Name", "$(BUILD.DEFINITIONNAME).html")
     $headers.Add("Document-SharePoint-Site", "https://acme.sharepoint.com/sites/mysite")
     
     $body = Get-Content -Path $(Build.ArtifactStagingDirectory)\MyDoc.html  -Raw -Encoding UTF8
     
     $response = Invoke-RestMethod $logicAppUrl -Method 'POST' -Headers $headers -Body $body -ContentType 'text/plain; charset=utf-8'
     
     Write-Host 'Upload to SharePoint via Logic App complete'
     Write-Host $response 

As you can see the powershell to do this is pretty easy and the Yaml for a pipeline is below.

steps:
- task: AzurePowerShell@5
  displayName: 'Upload Documentation to SharePoint via Logic App'
  inputs:
    azureSubscription: '[My Connection]'
    ScriptType: InlineScript
    Inline: |
     Write-Host 'Starting upload to SharePoint via Logic App'
     
     
     Write-Host 'Retrieving Logic App Url'
     $resourceGroup = '[My_RG]'
     $logicAppName = '[My_LA]'
     $triggerName = 'manual'
     $logicAppCallbackUrl = Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName $resourceGroup -Name $logicAppName -TriggerName $triggerName
     $logicAppUrl = $logicAppCallbackUrl.Value
     
     $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
     $headers.Add("Document-Path", "[SharePoint-Folder]")
     $headers.Add("Document-Name", "$(BUILD.DEFINITIONNAME).html")
     $headers.Add("Document-SharePoint-Site", "https://acme.sharepoint.com/sites/mysite")
     
     $body = Get-Content -Path $(Build.ArtifactStagingDirectory)\MyDoc.html  -Raw -Encoding UTF8
     
     $response = Invoke-RestMethod $logicAppUrl -Method 'POST' -Headers $headers -Body $body -ContentType 'text/plain; charset=utf-8'
     
     Write-Host 'Upload to SharePoint via Logic App complete'
     Write-Host $response 
    azurePowerShellVersion: LatestVersion

This opens up a few opportunities for us to expand our DevOps processes to do things like integrate with our support systems.

 

Buy Me A Coffee