Azure Resource Manager template deployment with Visual Studio - azure

I want to deploy resources to my Azure subscription with Visual Studio. I created a new "Azure Resource Group" project and see WebSite.json, WebSite.parameters.json and Deploy-AzureResourceGroup.ps1.
When I right-click on the project and choose "New Deployment" I can login to my subscription in the pop up window. But when I click the "Deploy" button I see in the output window my correct Account, TenantId, SbuscriptionId and Name but then only errors:
15:47:58 - [ERROR] New-AzureRmResourceGroup : Run Login-AzureRmAccount to login.
15:47:58 - [ERROR] At C:\Users\Frederic\Documents\Visual Studio 2015\Projects\AzureResourceGroup1\
15:47:58 - [ERROR] AzureResourceGroup1\bin\Debug\staging\AzureResourceGroup1\Scripts\Deploy-AzureR
15:47:58 - [ERROR] esourceGroup.ps1:96 char:1
15:47:58 - [ERROR] + New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Resource ...
When I open a PowerShell command window and run Login-AzureRmAccount first it works but what am I missing (or how to do it) with VS?

I was for three weeks in holidays and when I came back there was the Windows Anniversary Update and the new Azure SDK 2.9 that I installed and one of them has solved the problem. Now I can deploy Azure Resource templates from Visual Studio without problems :-)

Related

How to deploy Logic App from Visual Studio Community using powershell command?

I tried different ways to deploy my local logic app from VS Community using powershell but none of them are working.
Any solutions for this?
Logic App deployment successful from Visual Studio (local) through PowerShell Command
The following command worked for me
New-AzResourceGroupDeployment -ResourceGroupName <Azure-resource-group-name> -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.logic/logic-app-create/azuredeploy.json
and here is the output:
Here is the process that I followed before running the above command.
Process Flow:
I have found that there are 2 ways of deploying logic app through PowerShell i.e., Azure RM Template Commands and AZ Modules Commands
To work with any of the following commands, we are required to install related package files:
To deploy using Azure RM Template Commands - Run this code on PowerShell:
Install-Module -Name AzureRM -AllowClobber
To deploy using AZ module commands - Run this code on PowerShell:
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Checkout the following links to play with versions (uninstalling old and installing new), setting up the policies, connecting of Azure Accounts, etc in these:
Azure RM PowerShell Commands and Azure Az Module PowerShell Commands
Following is the process of which I have tried deploying the Local Visual Studio Logic App to Azure in PowerShell using Azure RM PowerShell Script commands:
Before deploying:
Create a Logic App in Visual Studio (File > New Project > Select 'Azure Resource Group' > Logic App)
Your solution will be ready in a few seconds, you will be able to see two json files. As you select prameters.json file you will be able to see json schema for logic app deployment.
To Connect your logic with your Azure Account, right click on LogicApp.json and select 'Open with logic app designer'. If you don't find this option, then install this extension in your project:
Right click on project and click on validate
Select your resource group, subscription and click on edit parameters - give custom name to your logic app. Otherwise, it will throw you error of null in logicAppName and shows template is invalid.
After validation, it shows the template is valid. It can be automatically validate during deployment process also, but it's good way to validate to get rid out of errors.
PowerShell Commands to deploy your logic App from visual studio (local):
Install this Power Shell provided by Microsoft Cloud.
Run in Administrator Mode > Login with Connect-AzureRmAccount command (it takes you to browser and connect with Azure account) > after that it imports your subscription and resource group details in the shell like below:
Use the following command to deploy your logic app
New-AzResourceGroupDeployment -ResourceGroupName "AzureAccountMail" -Templatefile "C:\LogicAppTemplats\template.json" -TemplateParameterFile "C:\LogicAppTemplats\parameters.json"
Check this following documentation for this command overview.
Done! Deployment Succeeded.
Now Check out in the azure portal:
Note:
Here you can find the template file and parameters.json file under your project:
Make Sure you given your logic app name value here in the parameters.json file:
And Provide the logic app name, deployment location values in the template.json file (LogicApp.json)

Azure powershell Move-AzureDeployment - error: HttpRequestException

We have a Cloud Service (Classic) swap using powershell in Azure pipelines that has worked all year, setup by a previous employee and now it is failing with error:
Move-AzureDeployment : An error occurred while sending the request.
At D:\a\_temp\blahblahblah.ps1:8 char:1
+ Move-AzureDeployment -ServiceName $servicename
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Move-AzureDeployment], HttpRequestException
+ FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.WindowsAzure.Commands.ServiceManagement.H
ostedServices.MoveAzureDeploymentCommand
The actual job task is using PowerShell Script set as inline with Error action as Stop. The actual script:
$subid = 'blah-blah-blah-blah'
$servicename = "blahblahblah"
Select-AzureSubscription -SubscriptionId $subid
Move-AzureDeployment -ServiceName $servicename
$service = Get-AzureDeployment -ServiceName $servicename -Slot Production
Start-Sleep -s 300
Remove-AzureDeployment -ServiceName $servicename -Slot "Staging" -Force
I was sure this was maybe a Service connection with Management Certificate expired but I have one valid working and found it is setup exactly like another similar pipeline/service connection that is working.
So the issue was two things, SSL and PowerShell version issues after updates. To deal with SSL issues I added this line to the top of our inline script:
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
And for the PowerShell issue it required changing to the Azure PowerShell app for pipelines, so we could roll back to a specific task version and the 4.2.1 PowerShell Version as seen in this answer:
Programmatically Swap Staging Slot to Production Slot in Azure Cloud Service
This might be the only way to swap a Cloud Service (Classic) these days. A little annoying Azure pushed this classic service and never properly maintained it.

Can I create an azure app using azure devops

I am trying to automate the process of an Azure Active Directory (AAD) app registration using Azure DevOps release pipeline but it fails to do so. (Please note that the same command (powershell commands as well as azure commands) works perfectly fine if I am running the same commands from my laptop) and for that I created an azure powershell task in the release pipeline and used the following line of code in the "inline script section":
I tried creating the AAD app registration using the following 2 methods:
1. "Azure Powershell script task"
2. Azure commands
Following is inline script that I used in case of azure powershell task:
Import-Module AzureRM
Import-Module AzureAD
# Register an AAD app
$appURI = "https://knaabdapp123.azurewebsites.net"
$appHomePageUrl = "https://knaabdapp123.knandan.in"
$appReplyURLs = #($appURI, $appHomePageURL, "https://localhost:12345")
New-AzureADApplication -DisplayName knaabdapp123 -IdentifierUris $appURI -Homepage $appHomePageUrl -ReplyUrls $appReplyURLs
I get the following error when I do so:
2019-08-09T11:27:31.1039145Z ##[section]Starting: Azure PowerShell script: Register an AAD app and generate credential for the same
2019-08-09T11:27:31.1162119Z ==============================================================================
2019-08-09T11:27:31.1162226Z Task : Azure PowerShell
2019-08-09T11:27:31.1162310Z Description : Run a PowerShell script within an Azure environment
2019-08-09T11:27:31.1162378Z Version : 2.153.1
2019-08-09T11:27:31.1162446Z Author : Microsoft Corporation
2019-08-09T11:27:31.1162520Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-powershell
2019-08-09T11:27:31.1162620Z ==============================================================================
2019-08-09T11:27:37.0179906Z ##[command]Import-Module -Name C:\Modules\AzureRm_5.1.1\AzureRM\5.1.1\AzureRM.psd1 -Global
2019-08-09T11:28:10.7554409Z ##[command]Clear-AzureRmContext -Scope Process
2019-08-09T11:28:11.2755157Z ##[command]Disable-AzureRmContextAutosave -ErrorAction Stop
2019-08-09T11:28:15.0230853Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud #processScope
2019-08-09T11:28:16.5226685Z ##[command] Select-AzureRMSubscription -SubscriptionId a*******-ae1c-****-****-********** -TenantId ***
2019-08-09T11:28:16.8648715Z ##[command]& 'C:\Users\VssAdministrator\AppData\Local\Temp\2a55****-67c6-****-8f80-**********.ps1'
2019-08-09T11:28:17.0308219Z ##[error]The specified module 'AzureAD' was not loaded because no valid module file was found in any module directory.
2019-08-09T11:28:19.0607544Z ##[command]Remove-AzureRmAccount -Scope Process -ErrorAction Stop
2019-08-09T11:28:19.4371114Z ##[command]Clear-AzureRmContext -Scope Process -ErrorAction Stop
2019-08-09T11:28:19.8885329Z ##[error]The term 'New-AzureADApplication' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I also used the Azure CLI task and used the following script, but that fails too:
az ad app create --display-name MyApplication123 --homepage "https://myapplication1232.nl" --reply-urls "https://localhost:12345" --identifier-uris "https://myapplication2.azurewebsites.net"
I get the following error in this case:
>az ad app create --display-name MyApplication123 --homepage "https://myapplication1232.nl" --reply-urls "https://localhost:12345" --identifier-uris "https://myapplication2.azurewebsites.net"
2019-08-09T11:47:46.5676945Z ERROR: Insufficient privileges to complete the operation.
2019-08-09T11:47:46.6721317Z ##[error]Script failed with error: Error: d:\a\_temp\azureclitaskscript1565351201021.bat failed with return code: 1
So, I have 2 questions:
Is it possible to create an AAD app registration using "Azure powershell" task script or "Azure CLI" task in Azure DevOps?
If yes, then what may I be doing wrong?
Is it possible to create an AAD app registration using "Azure
powershell" task script or "Azure CLI" task in Azure DevOps?
For this question, the answer is Yes, of course you can.
The cause of the error you received in Azure Powershell task is as default, the AzureAD powershell cmdlets will not be installed in agent.So, if you try to using this module directly, you will receive the message like "##[error]The specified module 'AzureAD' was not loaded because no valid module file was found in any module directory."
If yes, then what may I be doing wrong?
To solve this error message, please try with replacing your script Import-Module AzureAD as the follow script to use a correct way to get the AzureAD module.
$AzureADModulePath = $PSScriptRoot + "\AzureAD\2.0.1.16\AzureAD.psd1"
Import-Module $azureAdModulePath
This is the detailed info about AzureAD module in Powershell Gallery. And also, here has a blog you can refer.
Updated:
You must install AzureAD cmdlets module from the PowerShell gallery with the below script first:
Install-Module -Name AzureAD -RequiredVersion 2.0.1.16
Note: If get error like Install-Module : Administrator rights are required to install modules while you install with this script, please add -scope CurrentUser to the install script. It will running the script as administrator role.
And then, import the module from the installed path afterwards.

VSO/VSTS: Azure Powershell - The specified credentials cannot be used with the authentication scheme 'Basic'

I have the following build step which runs a script in Azure Powershell. The script basically publishes files to the web app (see further down for details).
This works just fine with all of my web apps EXCEPT FOR ONE. I get the following error:
scriptCommand= & "C:\a\8b0700333\MyProj\Scripts\Publish.ps1"
-websiteName mywebapp -packOutput "C:\a\8b0700333\MyProj\Api"
Stopping web app...
Publishing web app...
Publishing with publish method [MSDeploy]
[error]Error: The specified credentials cannot be used with the
authentication scheme 'Basic'.
[error]Error: Default credentials
cannot be supplied for the Basic authentication scheme.
[error]Parameter name: authType
[error]Error count: 1.
The Publish.ps1 script:
param($websiteName, $packOutput)
$website = Get-AzureWebsite -Name $websiteName
# get the scm url to use with MSDeploy. By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]
$publishProperties = #{'WebPublishMethod'='MSDeploy';
'MSDeployServiceUrl'=$msdeployurl;
'DeployIisAppPath'=$website.Name;
'Username'=$website.PublishingUsername;
'Password'=$website.PublishingPassword
'SkipExtraFilesOnServer'='False'}
Write-Output "Stopping web app..."
Stop-AzureWebsite -Name $websiteName
Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"
. $publishScript -publishProperties $publishProperties -packOutput $packOutput
Write-Output "Starting web app..."
Start-AzureWebsite -Name $websiteName
Had the same issue, the problem was coming from the fact that apparently the script Microsoft provides doesn't support slots.
Made a fixed version here https://gist.github.com/baywet/f7ed425c48ccde4399c7
Helping myself from this post How can I get the PublishUrl via Azure PowerShell?
This error usually occurs when using MS deploy HTTP Basic Authentication without any credentials specified. So you can add following code in the PowerShell script to check if the publish username and password for the web app is get correctly.
Write-Output $website.PublishingUsername
Write-Output $website.PublishingPassword
And also, check the value of msdeployurl to see if it is the correct URL (Usually like: youwebappname.scm.azurewebsites.net) for deployment.
Write-Output $msdeployurl

Publish-AzureServiceProject command failed for node.js application

I am following this tutorial to deploy node.js application from my machine to windows azure:
https://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/
my command is as below:
Publish-AzureServiceProject -ServiceName socketlistener -Location "East US" -Launch
but I am getting the following error
Publishing to Windows Azure. This may take several minutes...
1:32:36 PM - Preparing runtime deployment for service 'socketlistener'
1:32:38 PM - Preparing deployment for socketlistener with Subscription ID: ***...
1:32:40 PM - Verifying storage account 'socketlistener'...
Publish-AzureService : Path for package doesn't exist in D:\dev\node\socketlistener\cloud_package.cspkg.
At line:1 char:21
Publish-AzureService <<<<
CategoryInfo : CloseError: (:) [Publish-AzureService], FileNotFoundException
What I am suspecting is that there is some issue with your application configuration (Service Definition or Service Configuration) which is causing problem in package creation. The error message also suggests the same problem. Based on Publish-AzureServiceProject command execution the next step is to create the package after verifying the storage account. And after the package creation, the next step is to connect service endpoint which you can verify in the same link above you are following in tutorial.
To verify that there is no issue with your machine or connection to Windows Azure application, try creating a new Node.js application, add new web/worker role and do not make any changes in configuration then try deploying. This will verify if there is any issue with your machine configuration (if any) or other issue:
New-AzureServiceProject your_node_project
Add-AzureNodeWebRole
Publish-AzureServiceProject -ServiceName socketlistener -Location "East US" -Launch

Resources