如何使用Power Shell脚本在Azure中访问Kudu [英] How to access Kudu in Azure using power shell script

查看:92
本文介绍了如何使用Power Shell脚本在Azure中访问Kudu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Power Shell脚本访问Kudu.链接看起来像:https://adc-dev.scm.azurewebsites.net.我需要复制位于以上链接中D:\home\site\wwwroot\bin\apache-tomcat-8.0.33\webapps位置的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:\home\site\wwwroot\bin\apache-tomcat-8.0.33\webapps location in above link.

当前,我正在通过添加FTP任务使用VSTS部署war文件.但是在部署最新的war之前,我想在Azure Kudu位置的某些位置备份旧的war,例如:D:\home\site\wwwroot\bin\apache-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:\home\site\wwwroot\bin\apache-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构建/发行版中通过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(发布/api/command):

Regarding copy file through Kudu, you can use Command Kudu API (Post /api/command):

Kudu REST API

更新:

通过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 "site\wwwroot\bin\apache-tomcat-8.0.33\webapps" "copy xx.war ..\xx.war /y" "[resource group]" "[web app]"

这篇关于如何使用Power Shell脚本在Azure中访问Kudu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆