How to access Kudu in Azure using power shell script

前端 未结 3 596
执念已碎
执念已碎 2020-12-04 03:51

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 <

3条回答
  •  遥遥无期
    2020-12-04 04:20

    You can refer to this thread below to know how to call Kudu API through Azure PowerShell in VSTS build/release:

    Remove files and foldes on Azure before a new deploy from VSTS

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

    Kudu REST API

    Update:

    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]"
    

提交回复
热议问题