PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How do I deploy to Azure App Service with PowerShell (az module)?

 July 13, 2022     azure, azure-web-app-service, powershell, web-deployment     No comments   

Issue

I want to deploy app services from Powershell. I would like to use only publish profile (no password for azure account).

I tried FTP service, but sometimes files are blocked by running users. I think I have to stop app service.

There is powershell command like:

Publish-AzWebApp

However first I need login with:

Connect-AzAccount

and pass credentials what I want to avoid.

There is any way to call Publish-AzWebApp based on only publish profile (no login by account)?

Connect-AzAccount has other options to login (token or certificate). Unfortunately I don't know how to generate it.

BTW There was a topic about it: How do I deploy to Azure App Service with PowerShell? But it is old and now module "az" is recommended.


Solution

There is any way to call Publish-AzWebApp based on only publish profile (no login by account)?

No, you can't. If you want to use the Publish-AzWebApp , you always need to login with Connect-AzAccount, whatever the parameters you use, examples here.

If you want to use powershell to deploy the web app based on only publish profile, the workaround is to use Kudu API via powershell.

$username = "`$webappname"
$password = "xxxxxxx"
# Note that the $username here should look like `SomeUserName`, and **not** `SomeSite\SomeUserName`
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"

$apiUrl = "https://joywebapp.scm.azurewebsites.net/api/zipdeploy"
$filePath = "C:\Users\joyw\Desktop\testdep.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST -InFile $filePath -ContentType "multipart/form-data"


Answered By - Joy Wang
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing