When presenting to customers and partners my main goal is to plant a seed with knowledge about what technology can do in their work environment. To make this as memorable as possible I tried to find something tangible.
In researching about the automation and pipelines, I found these nice little Flic bluetooth buttons in a twitch session about Azure Functions. The flic button connects via Bluetooth to your phone or a Flic Hub and allow you run query towards any REST API. Some are nicely packaged integrations like Philips Hue, Telldus, or Nest. Others are not know to the system like Azure DevOps – Azure Pipelines.
My goal was to trigger a Azure Pipeline deployment using these buttons for my blue/green deployment demo. Click on the green button and the green deployment starts. Click on the blue button and the blue deployment starts.
This required a little bit of digging into the Azure Pipeline REST API to remotely trigger actions. But it surely is possible and actually fairly simple.
We have a POST HTTP request to perform to the correct URL where you fill in the organization and project name. The content type of the request body needs to be set and you need to figure out how to authenticate. The Authorization header is Basic which is a Base64 encoding of the following string without the quotes: “[username]:[personal access token]”. Replace the [xyz] below with the result of the base64 encoded string. To create the personal access token you can follow the guide here.
Keep in mind that token gives access to your DevOps environment so don’t keep it in git or any place that is public! In case of compromise or the slightest doubt revoke the token.
URL:
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=4.1
Header: Content-type: application/json Authorization: Basic [xyz]
Request body: { "definition": { "id": 13 } }
In Azure Devops this looks like the screenshot below. You have a deploy and destroy for both environments and in in the URL you can find thhe definition ID used in the request body.
Since this setup Apple has release iOS 12 with the new Shortcuts app. This this app allows you to automate parts of your phone. Instead of having the buttons I was wondering can I from my notification screen start or stop my demo environment?
REST API’s to the rescue again. Also here I could implement these HTTP call and run for example Azure CLI. In my Github ios-shortcut repo you can find my yaml pipeline definition. Fork this project to your own account and link GitHub with your Azure DevOps environment.
This pipeline does a search in Azure for all VM’s starting with a argument $Query you pass as a variable and starts the VM’s. In Azure Pipeline you also need to link your Azure Subscription and pass the name of it in a variable.
#
# Runs Azure CLI in Azure Pipelines to start Azure VM's
# where the name of the VM starts with the query variable
#
resources:
- repo: self
queue:
name: Hosted Ubuntu 1604
steps:
- task: AzureCLI@1
displayName: 'Azure CLI '
inputs:
azureSubscription: '$(AzureSubscription)'
scriptLocation: inlineScript
inlineScript: |
query="[?name.starts_with(@,'$1')].{id:id}"
echo " ####################################################################
# Starting VM's starting with the '$1' string ####################################################################"
az vm start --ids $(az vm list --query "$query" --output tsv)
arguments: '$(Query)'
In Azure Pipelines there are a few steps to take:
- Create a new pipeline with the visual designer and link it to the correct YAML file.
- Link the Azure DevOps project to the Azure Subscription you want access to.
- Add the Query and AzureSubscription variables to the pipeline. The name of the AzureSubscription variable is the name of service connection you created in the previous step.
- Disable any CI triggers as you want to do control this yourself with your button or shortcut.
Final step is to get the Shortcuts app and download the shortcut here. Fill in the fields and you can run this from this app, your homescreen, widget screen, …
You can even create a menu with that calls different pipelines all with a touch of a finger from the Widget screen.
With this you start your demo environment just before your meeting or build it using Azure Pipeline during your presentation!
Enjoy!
Be First to Comment