Reputation: 1397
I've searched a bit about this, but is there documentation at all on how to schedule jobs that run with Azure CLI commands?
I want to run in the cloud, but azure automation doesn't support CLI (yet), so i am leaning towards perhaps using Azure Scheduler... but don't know the pros and cons...
Alternatively, is it possible to create a scheduled job, somehow, in the Azure Cloud Shell... i assume this is backed by some VM and therefore perhaps if it is Linux based we could whizz up a cron job... i don't really know how to do that though.
Ta!
Upvotes: 6
Views: 7236
Reputation: 1343
You can use an AzureDevOps pipeline for this:
pr: none
trigger: none
schedules:
- cron: "0 7 * * 1-5"
displayName: "Working-hours (7 am UTC, Monday to Friday)"
always: true
branches:
include:
- master
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'PipelineServiceConnection'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az --version'
What you have to do is create a new pipeline via the AzureDevops Pipelines tab:
The yaml script uses a service connection called 'PipelineServiceConnection', to create such service connection see: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops
More info about AzureCLI task: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops
Configure scheduled pipelines: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml
Upvotes: 4
Reputation: 3421
I tried finding some information on how to use Azure CLI in the cloud but there doesn't seem to be much available.
There are two versions of Azure CLI:
npm install -g azure-cli
Azure Web Apps support running applications built ontop of node.js. Technically you could then install the v1.0 module in a Web App and run your script on a schedule there.
However, recommended is to use v2.0. But this would offere one possibility of automation.
Current Azure CLI is not support but it's under review at the time of writing. See this link for the uservoice suggestion and vote on it if this a desired feature.
As far as I can tell, there's no way to run Azure CLI on an Azure Function.
Azure Scheduler is a service for only invoking code hosted elsewhere. This would still mean you need to host your code somewhere else, i.e. cloud or on-premises, then have the scheduler run it for you.
Triggering mechanisms that are supported are:
It's a shell that contains tools needed for running commands and scripts without the needed to locally install anything. Scheduling anything, using cron does not seem to be possible.
At the moment, if you want to script something, and run it in the cloud, I recommend you have a look at PowerShell. Running PowerShell scripts, with a time trigger is possible on Azure Functions and support adding your own custom modules as well.
If you need to use Azure CLI and serverless, then you could run it inside of a Docker container and host the container in the cloud, e.g. in an Azure Container Instances. See this link on how to create it.
Upvotes: 9