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:
parameters:
- name: buildNumber
type: string
- name: extensionName
type: string
- name: socialmediaLogicAppURL
type: string
steps:
# Update the build number variable so the next build will be the next minor version
- task: richardfennellBM.BM-VSTS-BuildUpdating-Tasks-DEV.BuildVariableTask-Task.BuildVariableTask@1
displayName: 'Update Build Variable'
inputs:
variable: Minor
mode: Autoincrement
usedefaultcreds: false
# Get the PR title and hence the reason for the release
- task: richardfennellBM.BM-VSTS-ArtifactDescription-Tasks-DEV.ArtifactDescriptionTask.ArtifactDescriptionTask@1
displayName: 'Get Git Artifact PR Reason'
inputs:
OutputText: 'OutputedText'
# Post to the Logic App to create various social media posts
- pwsh: |
$msg = "I have just released Version ${{parameters.buildNumber}} of my Azure DevOps Pipeline ${{parameters.extensionName}} http://bit.ly/VSTS-RF $(OutputedText) "
write-host "Posting message: $msg"
$uri = "${{parameters.socialmediaLogicAppURL}}"
$body = "{ `"Message`": `"$msg`"}"
Invoke-WebRequest -Uri $uri -Method POST -Body $body -Headers $headers -ContentType "application/json"
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.
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.