Moving my Azure DevOps Pipeline generated social posts to Azure Logic Apps

I posted a while ago about how I had automated the generation of social media posts for my static Hugo based website using Azure Logic Apps.

The other place I auto-generate social media posts is from releases via my project's Azure DevOps Pipeline builds. These use a YAML Pipeline Template that calls a Marketplace task to post to Twitter and a PowerShell task to Invoke-WebRequest to post to Mastodon.

Recently the Twitter task started to fail, and given the recent changes to the Twitter API with the move to the V2 API, I decided a new solution was required.

I realised the simplest solution was to use another Azure Logic App sharing the connectors I had already created for my website posts. To make this change, my post build YAML template was greatly simplified to:

 1parameters:
 2- name: buildNumber
 3  type: string
 4- name: extensionName
 5  type: string
 6- name: socialmediaLogicAppURL
 7  type: string 
 8
 9steps:  
10# Update the build number variable so the next build will be the next minor version
11- task: richardfennellBM.BM-VSTS-BuildUpdating-Tasks-DEV.BuildVariableTask-Task.BuildVariableTask@1
12  displayName: 'Update Build Variable'
13  inputs:
14    variable: Minor
15    mode: Autoincrement
16    usedefaultcreds: false
17
18# Get the PR title and hence the reason for the release
19- task: richardfennellBM.BM-VSTS-ArtifactDescription-Tasks-DEV.ArtifactDescriptionTask.ArtifactDescriptionTask@1
20  displayName: 'Get Git Artifact PR Reason'
21  inputs:
22    OutputText: 'OutputedText'
23
24# Post to the Logic App to create various social media posts
25- pwsh: |
26   $msg = "I have just released Version ${{parameters.buildNumber}} of my Azure DevOps Pipeline ${{parameters.extensionName}} http://bit.ly/VSTS-RF $(OutputedText) "
27
28   write-host "Posting message: $msg"
29   $uri = "${{parameters.socialmediaLogicAppURL}}" 
30   $body = "{ `"Message`": `"$msg`"}"
31   
32   Invoke-WebRequest -Uri $uri -Method POST -Body $body -Headers $headers -ContentType "application/json"   
33  displayName: 'Create social media posts about new release'

I can now just update the Logic App to change to which social media platforms posts are generated.

Logic App Design

So, arguably a better solution as I am using each tool for the job it was designed for i.e handing off the orchestration of external systems to Logic Apps as opposed to managing it in the build pipeline.