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!
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:
v1.0
Built as a node.js module
Can be installed by running npm install -g azure-cli
v2.0
Standalone package
Install MSI on Windows or using some package manager, e.g. apt/yum/zyper/etc, on Linux.
Azure App Service
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.
Azure 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.
Azure Functions
As far as I can tell, there's no way to run Azure CLI on an Azure Function.
Azure Scheduler
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:
HTTP, HTTPS
Azure Storage queue
Azure Service bus queue
Azure Service bus topic
Azure Cloud Shell
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.
Suggestion
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.
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:
Choose the location for the pipeline script
Choose the branch
Choose the pipline template: "Starter pipeline"
Paste the above yaml code in the editor
Save and run the pipeline
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
Related
I would like to turn ON/OFF HTTPS Only of my website during the pipeline execution.
Set-AzWebApp -ResourceGroupName $(ResourceGroupName) -Name $(WebAppName) -HttpsOnly $flase
I am using private windows agent.
I am getting following issue
I have Az installed on my server.
Could you please help me?
To use Azure ClI task you need to follow below prerequisites
A Microsoft Azure subscription
Azure Resource Manager service connection to your Azure account
Microsoft hosted agents have Azure CLI pre-installed. However if you are using private agents, install Azure CLI on the
computer(s) that run the build and release agent. If an agent is
already running on the machine on which the Azure CLI is installed,
restart the agent to ensure all the relevant stage variables are
updated.
According to your error log, seems Azure CLI is either not installed properly or detected by Azure DevOps.
Please make sure you have restarted the build agent to ensure all the relevant stage variables are updated.
Besides, you could also try to use Azure CLI on the private agent directly check if you are able to use above Azure command to turn off https. This will also narrow down your issue.
I am trying to deploy my flask application on Linux web apps.
I want to set a azure pipeline for my code which is pushed on an azure repository.
I have made all the configuration changes in my python code and created a web app with runtime stack of Python 3.7
As soon as I go to deployment center to deploy my code, after selecting the azure repository as the source of my code, I am redirected to an option of azure pipelines where we have to configure our build settings.
But the build does not gives any option for Python. It just gives me four build options such as Node, Ruby, Asp.Net and php.
I cannot use :
- Docker
- Git
With such limitations I have found no suitable tutorial to do the same.
Can someone tell me some way to set the pipeline for my python project ?
Azure DevOps CI/CD works with any language, platform and cloud. Just for Python application, you may need add additional steps to achieve the deployment from Azure Devops CI/CD.
CI
Since the python is an interpreted language, do not need the compilation. If none of other step, like test, just need use 2 tasks in CI pipeline: Archive Files task and Publish Build Artifacts task.
The Archive Files task used to pack the python application source folder into a zip package to use it in CD. And Publish Build Artifacts task will publish this zip package to Release pipeline.
BUT,
If your project contains and needs test, please add another Command line task to run the test by using pytest.
But, in azure devops, you need configure the python environment with some tasks if you want to use python component like pytest.
Here please refer to this blog.
Note: Since the stack you are using is Python 3.7, please specify the python version as 3.x in the Using Python task.
CD
Since you have create the app service in Azure portal, just skip step 4(Add Azure CLI task) in Exercise 3: Configure Release pipeline which shown in this blog, because Step 4 just used to create a new Azure Resources.
1. To deploy the python application, you need add the Azure App Service manage task first to install the corresponding python version site extension in release pipeline:
It would install set of corresponding tools to support to manage your app service.
2. Next you could use Azure App Service deploy to deploy the zip package which created in the Build pipeline, to the app service you configured in Azure portal.
After specified the subscription in this task, the app service will automatically display in the drop list of App Service name:
Then specified the path which you configured in the publish task of the build pipeline. Replace $(Build.ArtifactStagingDirectory) as $(System.DefaultWorkingDirectory), and replace $(Build.BuildId) as * to search the zip package by using the fuzzy search.
We use Azure DevOps with a hosted VS2017 build agent. We would like to use the the new Az PowerShell module. However, the VS2017 hosted build agent has AzureRM installed on it. The documentation states You should not install Az side-by-side with AzureRM. Remove all AzureRM modules before installing Az. and this indeed is necessary because the two conflict. There is also no Az PowerShell build task.
So the question is, how do I use the Azure Az PowerShell module from an Azure DevOps hosted VS2017 build agent?
I suppose the answer is - you dont (for the time being). Because you wont have permissions to remove the azure powershell module. Ok, apparently you can do that.
Another way to make it work, use a docker container as a build agent (inside hosted agent). That can have Az module, obviously.
They cannot be installed side by side, however one can be installed in PowerShell (non core), and the other in PowerShell Core.
From the comments in the docs you specified:
Question: The document says not to install the modules side-by-side but is there any reason that we cannot run AzureRM in PowerShell 5.1 and AZ in PowerShell Core on the same machine?
Answer: No, no reason at all. In fact we are thinking of suggesting this as an advanced scenario for those with a substantial investment in AzureRM scripts
I'm struggling to understand how to run a powershell script (it just runs an exe) on the App Service after deployment using Azure Devops.
FYI - the exe just reads some config info in the web.config and does some database updates. So it needs access to the transformed web.config and the SQL Server database that the App Service has.
I've tried adding a Powershell step using a Release Pipeline deployment task, but it seems to only run on the Agent, which does not have the context that the exe needs.
I can run the script manually using the Kudu command line window tool, but I need to automate this thing.
I've seen a few SO articles like this: How to add a custom post deployment script to azure websites? or Kudu post-deployment commands not running but I think that only works when you use the inbuilt deployment mechanism for App Services. ie - I couldn't get it to trigger the script in post-deploy from Azure Devops.
This is in the comments above, but if people find it useful, the answer to this is
Using the Azure App Service Deploy task, expand Post Deployment Action, there's an option to run a script (or inline write one).
This will be executed as part of the app service deployment and should allow you to do what you want. It's run at the wwwroot folder so the files need to be present in your actual deployment (zip/folder).
I have a build pipeline that is working pretty well currently in Azure DevOps. As part of the pipline/build process, I create an artifact, which is published and reachable. After that, I'd like to do the following:
Create/Start Up a new VM (Windows)
Grab the now published artifact, unzip it and run the executable within
Run the integration tests
Close the VM
I've looked around the Azure documentation but cannot find much that discusses this sort of solution. Please help!
There is nothing built-in (like a readymade task create a vm), so you can use any way to create a VM in Azure. Azure powershell, Azure Cli, ARM Templates, SDK calls. whatever works for you.
You would need to open ssh\winrm to talk to that vm to deploy stuff to it. thats about it. You can find lots of examples on how to create a VM online. VSTS got tasks for Azure Powershell\Cli\ARM Tempaltes so you dont need to handle auth.
You can create a VM using ARM templates with the task 'Azure Resource Group Deployment'
With a separate task 'Powershell on target machine' you can run a powershell script on the target VM, if you put the downloading, unzipping and running of this exe in this script you should be able to perform the tasks you need.
You could also look into the 'invoke-azurermvmruncommand' powershell command, this allows you to run a powershell script in the vm. https://learn.microsoft.com/en-us/powershell/module/azurerm.compute/invoke-azurermvmruncommand?view=azurermps-6.11.0