Code description
This code snippet shows how to use deploy Azure Automation PowerShell runbooks using GitHub Actions workflow.
Automation Runbooks can be used to run scripts regularly including PowerShell workflows, Python scripts, etc.
If you have multiple scripts to deploy, you can create a PowerShell script file to deploy.
The following assumptions are made:
The PowerShell runbook script (myrunbook.ps1) is located in the specified folder (scripts/runbooks).
The runbook is PowerShell type.
GitHub Actions secrets are setup to use OIDC to authenticate with Azure.
The resource will be deployed into automation account named
myautomationaccount
under resource group 'rg
'.
Code snippet
# This workflow deploys Azure automation runbooks into Azure.
name: Deploy Kontext automation runbooks
on:
push:
branches: ["master"]
paths:
- "scripts/automation/**"
workflow_dispatch:
permissions:
contents: read
id-token: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Login to Azure
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# Deploy runbooks
- name: Deploy Azure runbooks
uses: azure/powershell@v1
with:
inlineScript: |
pushd ./scripts/runbooks
Import-AzAutomationRunbook -Path "myrunbook.ps1" -Name myrunbook -Type PowerShell -AutomationAccountName 'myautomationaccount' -ResourceGroupName 'rg' -Force
Publish-AzAutomationRunbook -Name myrunbook -AutomationAccountName 'myautomationaccount' -ResourceGroupName 'rg'
popd
azPSVersion: "latest"
# Logout
- name: logout
run: |
az logout