如何使用 Power Shell 脚本访问 Azure 中的 Kudu [英] How to access Kudu in Azure using power shell script
问题描述
我正在尝试通过 Power Shell 脚本访问 Kudu.链接类似于:https://adc-dev.scm.azurewebsites.net
.我需要复制位于上述链接中 D:homesitewwwrootinapache-tomcat-8.0.33webapps
位置的 war
文件.
I am trying to access Kudu through power shell script. Link looks like: https://adc-dev.scm.azurewebsites.net
. I need to copy war
file located in D:homesitewwwrootinapache-tomcat-8.0.33webapps
location in above link.
目前我正在通过添加 FTP 任务使用 VSTS 部署 war
文件.但是在部署最新的 war
之前,我想在 Azure Kudu 位置的某个位置备份旧的 war
,例如:D:homesitewwwrootinapache-tomcat-8.0.33
(war
位置的根文件夹).所以之后我可以删除 war
并在 Kudu 中部署最新的 war
文件.
Currently I am deploying the war
file using VSTS by adding FTP task. But before deploying the latest war
I would like to take backup of the old war
in some location in Azure Kudu location say like: D:homesitewwwrootinapache-tomcat-8.0.33
(root folder to the war
location). So after that I can remove the war
and deploy the latest war
file in Kudu.
如何做到这一点?我的意思是如何使用 power shell 脚本访问 kudu.请给我建议.
How to do this? I mean how to access kudu using power shell script. Please suggest me.
推荐答案
你可以参考下面这个线程,了解如何在 VSTS build/release 中通过 Azure PowerShell 调用 Kudu API:
You can refer to this thread below to know how to call Kudu API through Azure PowerShell in VSTS build/release:
删除文件和在从 VSTS 进行新部署之前在 Azure 上折叠
关于通过Kudu复制文件,可以使用Command Kudu API (Post/api/command):
Regarding copy file through Kudu, you can use Command Kudu API (Post /api/command):
更新:
通过 Kudu API 调用 Command 的简单示例:
Simple sample to call Command through Kudu API:
function RunCommand($dir,$command,$resourceGroupName, $webAppName, $slotName = $null){
$kuduApiAuthorisationToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $webAppName $slotName
$kuduApiUrl="https://$webAppName.scm.azurewebsites.net/api/command"
$Body =
@{
"command"=$command;
"dir"=$dir
}
$bodyContent=@($Body) | ConvertTo-Json
Write-Host $bodyContent
Invoke-RestMethod -Uri $kuduApiUrl `
-Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
-Method POST -ContentType "application/json" -Body $bodyContent
}
RunCommand "sitewwwrootinapache-tomcat-8.0.33webapps" "copy xx.war ..xx.war /y" "[resource group]" "[web app]"
这篇关于如何使用 Power Shell 脚本访问 Azure 中的 Kudu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!