View deployment history from the command line or PowerShell - azure-web-app-service

I am deploying through source control to a Microsoft Azure Website. It's a pain to log in to the Azure Portal and click through the UI to view the deployment history. Can we manage deployments from the command line or PowerShell?

Yes, you can use both the PowerShell or xplat (commandline) tools to do this.
More about installing them here:
http://azure.microsoft.com/en-us/documentation/articles/xplat-cli/
http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/
For the xplat use:
azure config mode 'asm'
site deployment list [options] [name]
site deployment show [options] <commitId> [name]
site deployment redeploy [options] <commitId> [name]
site deployment github [options] [name]
For PowerShell:
Get-AzureWebsiteDeployment [[-CommitId] <String>] [[-MaxResults] <Int32>] [-Details] [[-Name] <String>] [-Slot <String>] [<CommonParameters>]`
Get-AzureWebsiteDeployment -Name mySite
Also you can browse to https://{sitename}.scm.azurewebsites.net there you can also view your deployments using REST apis.

Azure CLI for Web Apps. We find the legacy Azure Service Manager mode easiest for this. Also, we find the output more readable in JSON. Using --max limits the results.
azure config mode asm
azure site deployment list MySiteName --max 1 --json
Azure CLI for Web App Slots. We can also retrieve a specific --slot.
azure config mode asm
azure site deployment list MySiteName --slot MySlotName --max 1 --json

Related

Functions get Remove when zip deploy function app using Azure CLI or PowerShell

I'm facing an issue while deploying the azure function using Azure CLI or Azure PowerShell.
I have already created needed resources like resource group, function app and blob storage.
My function app platform type is Linux with consumption plan and runtime net6.0. I have created Service Bus trigger function and deployed using Visual Studio Publish profile and it is working as expected.
But when I executed the command to deploy the Azure function using CLI. Command is executing successfully but when I open the function app from azure portal and go to functions blade the deployed functions do not appear there.
I also checked the folder structure of the build output as mentioned in the link
https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push
any help would be appreciated.
Thanks
Reproduced the same issue from our end using Az-CLI
az functionapp deployment source config-zip -g <Resource Group> -n <Function App Name> --src <Function Project with Zip>
Workaround to fix the issue
After setting SCM_DO_BUILD_DURING_DEPLOYMENT to true in Configuration > Application Settings of the Azure Function App in Portal and deployed again using AZ CLI commands and shown the functions in Portal and in Kudu site of wwwroot folder.
AZ CLI Command:
az functionapp deployment source config-zip -g HariTestRG -n KrishNet6FuncApp --src "C:/Users/Hari/source/repos/DotNet6/TimerTrigger1205.zip"
According to this MS DOC, we came to know that some deployment customization has to be done before deploying the Function App as a Zip Push, i.e., by default the app setting SCM_DO_BUILD_DURING_DEPLOYMENT is false which enables the continuous integration deployment.
For the PowerShell Workaround, refer GitHub Page.
Function App running on Linux OS in consumption plan has limited deployment options but supports only remote build.
To enable remote build on Linux, the following application settings must be set:
ENABLE_ORYX_BUILD=true
SCM_DO_BUILD_DURING_DEPLOYMENT=true
If your project needs to use remote build, don't use the
WEBSITE_RUN_FROM_PACKAGE app setting.
Functions Core Tools is the only solution work for me.
By default, Azure Functions Core Tool perform remote builds when deploying to Linux. Because of this, it automatically create these settings for you in Azure.
func azure functionapp publish <FunctionAppName>
my custom script file
param(
[Parameter(Mandatory=$True)]
$AppName,
[Parameter(Mandatory=$True)]
$LocalProjectPath
)
cd "$($LocalProjectPath)"
func azure functionapp publish $AppName
cd ..
if you need more help with Linux hosting use this link Zip Deploymnet to get detailed information related to Azure Functions Deployments.

Possible to enable diagnostic settings when creating an Azure VM via CLI?

I haven't found a command line switch for enabling diagnostic settings when creating a VM with the Azure CLI.
I know it works in the portal, but likely this is a separate step in the deployment template.
However, there is a new command line switch for enabling log analytics workspace immediately (Preview).
az vm create cli does not provide the arguments about diagnostic settings, so I am afraid that we cannot enable diagnostic settings when creating an azure vm.
As workaround, you can try to enable the diagnostics settings using Azure CLI by following this document.
az vm diagnostics set --settings
[--ids]
[--no-auto-upgrade {false, true}]
[--protected-settings]
[--resource-group]
[--subscription]
[--version]
[--vm-name]
Here is a case on github you can refer to .

Deploy of Arm Template with Logic Apps throws Error : Data sinks can’t be reused in different settings on the same category for the same resource

So I have setup a deployment of an Arm Template with some Logic Apps with some related diagnostic setting for Event hub, see img.
Event Hub Settings
However, when deploying the same template again, we get the error: "Data sinks can’t be reused in different settings on the same category for the same resource".
And the solution is to remove the diagnostic settings before a new deploy. But I don't want to manually do this each time we do a new deploy.
Have someone figured out a workaround for this?
Thanks!
You can either use PowerShell command or Azure CLI command to remove a diagnostic setting for the resource.
PowerShell command (You can find the documentation here):
Remove-AzDiagnosticSetting -ResourceId "Resource01" -Name myDiagSetting
Azure CLI command (You can find documentation here):
az monitor diagnostic-settings delete --name "myDiagSetting" --resource "Resource01"

AzureRm Add-AzureCertificate equivalent in Az

Ahead of the deprecation of the AzureRM powershell cmdlets later this year I am updating some of our infrastructure scripts to use the Az powershell cmdlets rather than AzureRM.
One of our scripts uploads SSL certificates to Azure Cloud Service(Classic) resources using Add-AzureCertificate:
Add-AzCertificate -ServiceName $serviceName -CertToDeploy $certObject
where $certObject is a X509Certificate2 object.
What is the equivalent cmdlet in the Az module? Add-AzCertificate does not exist.
On the Cloud Service documentation page where it details configuring SSL, only certificate upload via the Azure portal is shown.
As the comment from #Alex AIT, before call the AzureRM commands, you can run Enable-AzureRmAlias cmdlet which enables a compatibility mode through aliases, to allow you to use existing scripts with minimal modification while working towards a full migration to Az. For more information, you could refer to Migrate existing scripts to Az.
Also, to call Azure Cloud Service(Classic) resources, you still need Azure modules. View this example- Az / AzureRM / Legacy Azure Powershell Conflicts.

Add Application Insights to an azure function with Azure CLI

I have a PowerShell script which creates an azure function app on a consumption plan and its associated storage account within a resource group using the azure cli following the example In the Microsoft Docs
However to enable application insights I have to go to the azure portal, find the func select monitor and click enable application insights.
How can I expand that script to enable automate this step for the newly created function? I have been unable to find any specific documentation or examples and I would prefer to avoid resource templates if possible.
OF course, you could enable Application Insights to the azure function by Azure CLI.
But you need to create the Application Insights in the portal first, currently, it is unable to create Application Insights via Azure CLI.
You could follow the steps below.
1.Go to your Application Insights in the portal, copy the Instrumentation Key in the screenshot.
2.After creating the function app by your command , just use the CLI command below.
az functionapp config appsettings set --name <functionname> --resource-group <resourcegroupname> --settings 'APPINSIGHTS_INSTRUMENTATIONKEY = <Instrumentation Key>'
It works fine on my side, you could check it in the portal.

Resources