I am deploying my application from Github and I have three different deployment slot(Dev/Staging/prod) and would like to deploy the code only to Dev and swap the deployed code to the rest of the stages.
Just to not I don't have any pipeline tool yet so would like to understand with command line or GUI option as it is proof of concept.
You could use Azure CLI or powershell to access it.
Azure CLI:
# Replace the following URL with a public GitHub repo URL
gitrepo=https://github.com/Azure-Samples/php-docs-hello-world
webappname=mywebapp$RANDOM
# Deploy code from a public GitHub repository.
az webapp deployment source config --name $webappname --resource-group myResourceGroup \
--repo-url $gitrepo --branch master --manual-integration
Azure Powershell:
# Replace the following URL with a public GitHub repo URL
$gitrepo="https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"
$webappname="mywebapp$(Get-Random)"
$location="West Europe"
# Configure GitHub deployment from your GitHub repo and deploy once.
$PropertiesObject = #{
repoUrl = "$gitrepo";
branch = "master";
isManualIntegration = "true";
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName myResourceGroup -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web -ApiVersion 2015-08-01 -Force
After publishing it to azure, you could swap the slot via the portal, also the azure Powershell and CLI.
Related
I have a number of instance running under my app service in Azure. I need to get back all the id's of these instances.
I am currently using
Get-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceType
Microsoft.Web/sites/instances -Name $WebAppName -ApiVersion 2016-03-01
But is there an equivalent command using the az cmdlets ?
I've tried the exact PowerShell command that you executed in Azure PowerShell. I could be able to get the expected results as shown:
I've tried to get the desired outcome with AZ cmdlet(Bash) and received the expected results using:
az webapp list-instances
To get the instances running info with their respective ID's on app service in Azure:
az configure --defaults group=xxxxResourceGroupName
az configure --defaults web=xxxxwebapp
az webapp list-instances --name xxxxwebappp --resource-group xxxxResourceGroupName
If you want to retrieve "default hostname, EnabledHostName as well as state" of WebApp, Use below command as shown:
Refer MSDoc az.webapp cmdlets
It is always recommended to use latest Az PowerShell module cmdlets instead of AzureRM since AzureRm is going to retire soon.
In the above answer shared by #jahanvi replace Get-AzureRMResource with Get-AzResource which is a relevant Az module cmdlet.
Alternatively, you can use the Azure Management RestAPI to get the list of instances running under a particular webapp using Invoke-RequestMethod you call the rest api from powershell as well.
Here is the sample script:
Connect-AzAccount
$context=Set-AzContext -Subscription "<subscriptionId>"
$token = Get-AzAccessToken
$authHeader=#{
'Content-Type'='application/json'
'Authorization'='Bearer '+ $token.Token
}
$instances=Invoke-RestMethod -Uri https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Web/sites/<WebAppName>/instances?api-version=2022-03-01 -Method GET -Headers $authHeader
$instances.value.id
Here is the sample screenshot for reference:
I've been following this guide to cloning an existing app. I'm running the Az Powershell Module via Docker.
Here's what I ran:
$destapp = New-AzWebApp -ResourceGroupName HLP-API-NEW -Name hlp-api-new -Location "UK South" -AppServicePlan hlp-api-plan-new -SourceWebApp $srcapp
HLP-API-NEW is a new resource group that I created; hlp-api-plan-new is likewise a new service plan.
Here's how I got $srcapp:
$srcapp = Get-AzWebApp -ResourceGroupName HLP-API -Name api-hlp
The service plan / resource group nams are definitely correct. I get the following error:
New-AzWebApp: Long running operation failed with stauts 'InternalServerError'
Does anyone know why this might be?
Please make sure your app is not under the below conditions. if it is in the below condition, we can't be able to clone it.
Restrictions to clone app
Auto scale settings are not cloned
Backup schedule settings are not cloned
VNET settings are not cloned
App Insights are not automatically set up on the destination app
Easy Auth settings are not cloned
Kudu Extension are not cloned
TiP rules are not cloned
Database content is not cloned
Outbound IP Addresses changes if cloning to a different scale unit
Not available for Linux Apps
Managed Identities are not cloned
Not available for Function Apps
If your app is not in the above criteria, you can clone it.
Ways follows
1. Using Slot parameter
To clone an existing app including all associated deployment slots, you need to use the Slots parameter.
$srcappslot = Get-AzWebAppSlot -ResourceGroupName <Your Resource Group> -Name <Your app name> -Slot <slot name>
$destapp = New-AzWebApp -ResourceGroupName <Your Resource Group> -Name <Your new app name> -Location <location to create app> -AppServicePlan <App service plan name> -SourceWebApp $srcappslot
2. Using the new App Service plan
$srcapp = Get-AzWebApp -ResourceGroupName <Your Resource Group> -Name <Your app name>
New-AzAppServicePlan -Location "Central US" -ResourceGroupName <Your Resource Group> -Name <App Service plan Name> -Tier Standard
$destapp = New-AzWebApp -ResourceGroupName <Your Resource Group> -Name <new app name to create> -Location <Location to create app> -AppServicePlan <Your new app service name> -SourceWebApp $srcapp
3. Using Existing App Service plan
$srcapp = Get-AzWebApp -ResourceGroupName <Your Resource Group> -Name <Your app name>
$destapp = New-AzWebApp -ResourceGroupName <Your Resource Group> -Name <new app name to create> -Location <Location to create app> -AppServicePlan <Specify exact App service file path (APP SERVICE PLAN> PROPERTIES>RESOURCEID)> -SourceWebApp $srcapp
I have the same problem, I don't understand what's wrong with my command. While scouring the Internet I found this command which is leading me towards a solution. You may find it helpful as well:
PS> Resolve-AzError
This provided me the clue I needed to chase:
Message : Long running operation failed with status 'InternalServerError'.
ServerMessage : Restore failed with errors: Detail: Hostname 'abc.somedomain.com' conflicts with an already existing hostname.
ExtendedCode: 04005
Good luck!
We have windows webapp in Azure, we want to change the stack to dotnet core version(3.1,2.1) using Azure cli.
If it is a linux webapp, we can use az webapp config set -g $group -n $webappName --linux-fx-version "DOTNETCORE|2.1". But for windows couldn't find anything. Help is appreciated.
Thank you!
In our local environment(webapp is running on Windows app service plan), using the below cmdlet initially we have changed the .Net version to 6.0
az webapp config set -g "<RGName>" -n "<WebAppName>" --net-framework-version "v6.0"
later, we have downgraded the version(v4.0) using the below cmdlet & we are able to get the .NetCore(3.1,2.1) in our webapp configuration.
az webapp config set -g "<RGName>" -n "WebAppName>" --net-framework-version "v4.0"
Using the below powershell script, am able to achieve this.
Set-AzWebApp -ResourceGroupName 'MyRG' -Name 'MyWebApp' -AppServicePlan ' MyWebAppPlan'
$PropertiesObject = #{"CURRENT_STACK" = "dotnetcore"}
New-AzResource -PropertyObject $PropertiesObject -ResourceGroupName 'MyRG' -ResourceType Microsoft.Web/sites/config/metadata -ResourceName 'MyWebApp' -ApiVersion 2021-03-01 -Force
Refer this github issue for more information:- https://github.com/Azure/azure-cli/issues/21192
My deployment script uses PowerShell with the AzureRM module. I am trying to find the equivalent of the following Azure CLI call. That call creates an Azure Function based on a Docker image.
az functionapp create --name <app_name> --storage-account <storage_name> --resource-group myResourceGroup --plan myPremiumPlan --deployment-container-image-name <docker-id>/mydockerimage:v1.0.0
Anybody has an idea what is the PowerShell/AzureRM equivalent of "az functionapp create"?
If your ideal goal is to deploy a function app, there are multiple ways to create one.
You can use the below AzureRm command to provision / create a new Function App
New-AzureRmResource -ResourceType ‘Microsoft.Web/Sites’ -ResourceName $functionAppName -kind ‘functionapp’ -Location $location -ResourceGroupName $resourceGroupName -Properties #{} -force
Or You can use a ARM Template to deploy a function app - Details
Or you can use Zip Deploy to deploy your function app. -
As HariHaran said, there are several ways to create new function app. But if you want to create function based on docker image, it may be difficult to implement if use "New-AzureRmResource". So I think you can install az module in powershell, you can continue use "az functionapp create" commmand, you can refer to this tutorial to install it. But az module will not be compatible with AzureRM, so we'd better uninstall AzureRM before that, you can refer to this page about the compatible of az module and AzureRM.
You can use the New-AzFunctionApp cmdlet which is part of the Az.Functions module. This module is currently in Preview.
# First install PowerShell 6 or 7 from https://github.com/PowerShell/PowerShell/releases
# To install the Az.Functions module, Open PowerShell and run:
Install-Module -Name Az.Functions -AllowPrerelease
Alternatively, you can download it from https://www.powershellgallery.com/packages/Az.Functions/0.0.1-preview
For feedback and requests, please file an issue at https://github.com/Azure/azure-powershell/issues. Make sure you include in the title [Az.Functions]. Thanks!
How can I use Restore-AzureRmWebAppBackup to restore an app service to a different existing site? This can usually be done in the portal, but for some reason the destination app service is not listed, even though it's in the same resource group.
How can I use Restore-AzureRmWebAppBackup to restore an app service to a different existing site?
Here is a sample code of restore web app from PowerShell.
$resourceGroupName = "target web app resource group name"
$appName = "target web app name"
$blobName = "backup blob name"
$storageAccountURL = "SAS URL of your blob container"
Restore-AzureRmWebAppBackup -ResourceGroupName $resourceGroupName -Name $appName -StorageAccountUrl $storageAccountURL -BlobName $blobName -Overwrite
We can find the blob name from the restore page after you backup your web app.
For more information, link below is for your reference.
Use PowerShell to back up and restore App Service apps
Following is the solution using Bash CLI:
prerequisite: A storage account with a container and the container URL for the same. The container URL contains the access the key (SAS). More information about the container URL can be found here: https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
You can also use the following command to generate the SAS token:
az storage container generate-sas --name <container-name> --expiry <sas-expiry> --permissions <permissions> --account-name <account-name> --account-key <account-key>
To clone the app, use the following commands:
backupname=appname_`date "+%Y%m%d%H%M%S"`
az webapp config backup create --resource-group $OriginresourceGroupName --webapp-name $originAppName --backup-name $backupname --slot $OriginSlotName --container-url "$ContainerURL"
az webapp config backup restore --backup-name $backupname --container-url $ContainerURL --resource-group $TargetresourceGroupName --webapp-name $TargetAppname --overwrite --ignore-hostname-conflict
Use below cmdlets to restore last successful backup to slot or app
$resourceGroupName = "<<RG NAME>>"
$primarywebappname = "<<APP NAME>>"
$slotname = "<<SLOT NAME>>"
# Get the last Sucessfull BackupID of the backup you want to restore
$backupID=Get-AzWebAppBackupList -ResourceGroupName $resourceGroupName -Name `
$primarywebappname|where BackupStatus -EQ "Succeeded" |select -Last 1 |select BackupId
# Get the backup object that you want to restore by specifying the BackupID
$backup = (Get-AzWebAppBackupList -ResourceGroupName $resourceGroupName -Name
$primarywebappname | where {$PSItem.BackupId -eq $backupID.BackupId})
# Restore the app by overwriting it with the backup data in the slot
$backup |Restore-AzWebAppBackup -Slot $slotname -IgnoreConflictingHostNames -Overwrite
# Restore the app by overwriting into the exsisting App
$backup |Restore-AzWebAppBackup -Overwrite