I am trying to deploy a new version of WebJobs. I have webjobs.yml file like;
pool:
vmImage: 'ubuntu-latest'
if I try to stop like below, I am receiving error;
- task: InvokeRESTAPI#1
inputs:
connectionType: 'connectedServiceNameARM'
azureServiceConnection: '$(apiName)'
method: 'DELETE'
urlSuffix: 'https://$(apiName).scm.azurewebsites.net/api/triggeredwebjobs/$(apiName)-webjobs'
waitForCompletion: 'true'
WebJobs-API documentation
Step references task InvokeRESTAPI at version 1.152.1 which is not valid for the given job target
And if I use pool: server, as suggested I cannot execute other tasks.
also I tried to use STOP/START like below. It stops AppService but not WebJobs.
- task: AzureAppServiceManage#0
inputs:
azureSubscription: '$(apiName)'
Action: 'Stop Azure App Service'
WebAppName: '$(apiName)'
And I am eventually getting error from Azure:
The process cannot access the file XYZ because it is being used by another process.
So, how I can stop currently running WebJobs from Azure Pipelines, and deploy new version?
There are two solutions here, you can refer to:
The first is you can set this sticky app setting on the staging slot:
WEBJOBS_STOPPED: 1
Set this setting to 1 to disable running any job (will also stop all currently running jobs) Source : Kudu Wiki,case
The second is you can use Invoke-AzureRMResourceAction command. Adding Azure PowerShell task to definition. Source: case1 case2.
Invoke-AzureRmResourceAction -ResourceGroupName XXX -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName [web app name]/[web job name] -Action [start/stop] -ApiVersion 2015-08-01 -Force
I used inline script in Azure Cli task to update appsettings:
To stop all:
az webapp config appsettings set --name MyAppServiceName --resource-group MyAppServiceResourceGroup --subscription MyAppServiceSubscription --settings WEBJOBS_DISABLE_SCHEDULE=1 WEBJOBS_STOPPED=1
Related
In my Azure DevOps pipeline, I'm deploying a logic app on Azure but I get this warning:
##[warning]"ZipDeploy Validation WARNING: It is recommended to set app setting WEBSITE_RUN_FROM_PACKAGE = 1 unless you are targeting one of the following scenarios:
1. Using portal editing.
2. Running post deployment scripts.
3. Need write permission in wwwroot.
4. Using custom handler with special requirements.
NOTE: If you decide to update app setting WEBSITE_RUN_FROM_PACKAGE = 1, you will have to re-deploy your code."
Is it possible to suppress this warning?
Make sure to add the application settings to allow zip deploy like below:-
- task: AzureCLI#2
inputs:
# TODO: Fill in with the name of your Azure service connection
azureSubscription: ''
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az functionapp config appsettings set --name $(LAname) --resource-group $(resourceGroupName) --settings "BLOB_CONNECTION_RUNTIMEURL=$(blobendpointurl)"
az functionapp config appsettings set --name $(LAname) --resource-group $(resourceGroupName) --settings "WORKFLOWS_RESOURCE_GROUP_NAME=$(resourceGroupName)"
az functionapp config appsettings set --name $(LAname) --resource-group $(resourceGroupName) --settings WEBSITE_RUN_FROM_PACKAGE=1
addSpnToEnvironment: true
useGlobalConfig: true
Powershell task with app service plan
- task: AzurePowerShell#5
inputs:
azureSubscription: 'MyAzureSubscription'
ScriptType: 'InlineScript'
Inline: |
Set-AzWebApp -Name MyWebApp -ResourceGroupName MyResourceGroup -AppSettings #{'WEBSITE_RUN_FROM_PACKAGE'='1'}
azurePowerShellVersion: 'LatestVersion'
Make sure you change the deployment-method in your YAML pipeline to deploymentMethod: ‘runFromPackage’ instead of ‘zipDeploy’ like below:-
To :-
And then run your pipeline to allow zip deployment of Azure Logic app.
Reference:-
AzureFunctionApp#1 Gives a warning about something it removes itself · Issue #17580 · microsoft/azure-pipelines-tasks · GitHub
I'm trying to create an Azure DevOps pipeline to run a few Runbooks by a specific order.
My pipeline currently looks like the following:
trigger: none
pool: <mypool>
jobs:
- job: AzureCLI
steps:
- task: AzureCLI#2
inputs:
azureSubscription: '<mysubscription'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az automation runbook start --automation-account-name "myaccount" --resource-group "myrg" --name "runbook-1"
az automation runbook start --automation-account-name "myaccount" --resource-group "myrg" --name "runbook-2"
Thing is, when I run it like that what it does is triggering both runbooks in parallel. It triggers runbook-1 and then triggers runbook-2 without waiting for runbook-1 to finish.
In the Az CLI Docs there is no parameter like --wait-for-compellation or something like that.
There is a different command: 'az automation runbook wait' which I thought might wait after triggering the runbook with 'az automation runbook start' but it doesn't, it just exits immediately.
Anyone knows a different way to make the command hang until compellation?
I am trying to run a script in the Azure Powershell Task in Azure DevOps that uses AzureRM commands. I tried to use Task version 4.* and 5.*. Both of them are giving error saying that the AzureRM commands couldnt be recognized. (eg. Get-AzureRmResourceGroup is not recognized). What should I do to solve this issue?
You have there Az Modules available not AzureRM so if you try this
- task: AzurePowerShell#5
continueOnError: true
inputs:
azureSubscription: 'rg-the-code-manual'
ScriptType: 'InlineScript'
Inline: 'Get-AzResourceGroup -Name "TheCodeManual"'
azurePowerShellVersion: LatestVersion
You should get your result.
And if you want you may try to uninstall Az modules and then install AzureRm module. Here you have example how to uninstall az modules.
Here is a simple solution:
You may also take a look here to see how to force installation.
I am facing an implementation issues with the below scenario using Azure DevOps pipelines
Provision two resources in Azure Subscription using ARM templates
Azure Container Registry
Azure Kubernetes Services
Deploy the containerized application code to the Kubernetes clusters
I am able to perform both of the steps in an individual pipelines. Need some help with combining/integrating two pipelines into one.
How can I automate both of the above steps without having any manual intervention in the process. The process must be robust enough to handle the Application deployment in the same ACR and AKS that was created in the previous step?
Both the Infrastructure and the Application code resides in the same GIT/ Azure Repository.
First of all. I would like to recommend that you do not tie the two pipeline together.
While infrastructure as code is important and should be used. It is important to decouple the infrastructure provisioning from the application provisioning for many good reasons.
Regarding you ask, you should have a task that create the ACR/AKS, one task that gets the credentials to be used in another task which would deploy to the ore created AKS ans ACR
The flow could be.
ACR —AKS (if you want to configure your AKS with ACR integration, you need to have them sequential) — docker build/push to ACR — deploy container using shell script with KubeCTL leveraging the credentials from second step.
You can use multiple stages in one yaml pipeline. See below simple example:
Below yaml pipeline has two stages. The first stage do the tasks to provision the Infrastructure. The second stage is dependsOn the first stage, and defined the ACR and AKS in the variables, then do the tasks to deploy to the Kubernetes clusters.
trigger:
- master
stages:
- stage: Infrastructure Deployment
pool:
vmImage: windows-latest
jobs:
- job: Infrastructure
steps:
- task: AzureResourceManagerTemplateDeployment#3
inputs:
.....
- stage: Application Deployment
dependsOn: Infrastructure Deployment
pool:
vmImage: windows-latest
variables:
ACRName: "ACRName"
AKSName: "ACRName"
azureSubscriptionEndpoint: ..
azureContainerRegistry: ..
azureResourceGroup: ..
jobs:
- job: Application
steps:
# - task: Docker#2
# inputs:
# containerRegistry: $(ACRName)
# ...
- powershell: |
# Log in to Docker with service principal credentials
docker login $(ACRName).azurecr.io --username $SP_APP_ID --password $SP_PASSWD
docker build
docker push
- task: Kubernetes#1
displayName: kubectl apply
inputs:
connectionType: Azure Resource Manager
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(AKSName)
....
Update: dynamically capture the ACR and AKS name along with ACR login credentials
You can use azure powershell task to get above data. In order to use azure powershell task, you need to create a azure resource manager service connection.
Then you can write custom inline scripts in the task. See below example:
- task: AzurePowerShell#5
name: AzurePowershell
inputs:
azureSubscription: 'Microsoft Azure Internal Consumption (daaeef3e-d7fe-49e8-baaa-b3df9d072825)'
ScriptType: InlineScript
Inline: |
$json = (Get-Content "$(system.defaultworkingdirectory)\template.json" -Raw) | ConvertFrom-Json
$AKS = $json.resources | where {$_.type -eq "Microsoft.ContainerService/managedClusters"} | select name
$ACR = $json.resources | where {$_.type -eq "Microsoft.ContainerRegistry/registries"} | select name
echo "##vso[task.setvariable variable=ACRName;isOutput=true]$($ACR.name)"
echo "##vso[task.setvariable variable=AKSName;isOutput=true]$($AKS.name)"
$ACRCred = Get-AzContainerRegistryCredential -ResourceGroupName "MyResourceGroup" -Name $($ACR.name)
echo "##vso[task.setvariable variable=UserName;isOutput=true]$($ACRCred.Username)"
echo "##vso[task.setvariable variable=Password;isOutput=true]$($ACRCred.Password)"
azurePowerShellVersion: LatestVersion
You can then get these variables in the following stage by referring to stageDependencies.stageName.jobName.outputs['stepName.variableName']
See here for more azure powershell cli.
As a part of my yml pipeline definition, I have a AzurePowerShell#4 task, following is an extract from my pipeline definition
stages:
- stage: DeployDemoCluster
jobs:
- job: 'DeployAKSAndAll'
pool:
vmImage: 'windows-latest'
steps:
- task: AzurePowerShell#4
displayName: Store AI instrumentation key for Inbound Processor in central KeyVault
inputs:
azureSubscription: 'service-connection'
azurePowerShellVersion: LatestVersion
pwsh: true
ScriptType: 'FilePath'
ScriptPath: 'AKS/ps/update_kv_firewall.ps1'
The issue is, within my update_kv_firewall.ps1, all the powershell commands fail with the error, for example:
[error]Login-AzureRmAccount : The term 'Login-AzureRmAccount' is not recognized as the name of a cmdlet, function, script file, or operable program.
The script when executed individually / standalone, works perfectly fine.
what am I missing here?
As per your comment: the command "Get-AzKeyVault" runs without any errors, while 'Get-AzureRmVirtualNetwork' leads to errors.
Then I'm sure that you're installing the new Az module of azure powershell. So the command like Get-AzKeyVault can work.
Since you're installing Az module, please use all the commands from Az module. Almost each azure Rm command has an equivalent azure Az command, you can find it from the Az command list.
Note: the command like Get-AzureRmVirtualNetwork / Login-AzureRmAccount is from azure RM module, which will be retired this year later.