projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.12k stars 655 forks source link

Deployment status after synchronous zipdeploy #2630

Closed nikolaia closed 4 months ago

nikolaia commented 6 years ago

In regards to #2562 and https://github.com/projectkudu/kudu/wiki/Deploying-from-a-zip-file

Loving the Zipdeploy feature as I can write my deployment scripts using FAKE (.deployment -> deploy.cmd -> deploy.fsx - all present in the .zip artifact) and can write a smart pipeline for what needs to be done for my WebApps in the same DSL as my buildscript for creating the artifact (since kudusync works offline I can test the scripts 100% on my own machine, so awesome!):

"KuduStageFiles"
    ==> "MigrateDatabase"
    ==> "Deploy"
    ==> "SmokeTests"

However I'm having some trouble getting VSTS to fail when the deployment fails in Kudu (I'm running the call synchronous from an Azure CLI step in VSTS).

This script can be run from my own machine, and is in source control with the build and deployment scripts (again: Awesome!). It is the script called by VSTS:

Param(
    [Parameter(Mandatory=$True,Position=1)]
    [string]$appName
  )

$token = (ConvertFrom-Json -InputObject ([string](Invoke-Expression -Command:"az account get-access-token")))."accessToken"
$bearerToken = "Bearer $token"
$apiUrl = "https://$appName.scm.azurewebsites.net/api/zipdeploy"

$artifactDir = split-path -parent $MyInvocation.MyCommand.Definition
$zip = Get-ChildItem -Path $artifactDir -Filter *.zip | Select-Object -First 1
$zipPath = "$artifactDir/$($zip.Name)"

Write-Host "Calling $apiUrl with $zipPath using token '$bearerToken'"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=$bearerToken} -Method POST -InFile $zipPath -ContentType "multipart/form-data"

Seems like I'm just getting 200 OK back from the zipdeploy endpoint, even if the deployment script failed and the deployment is not active. Do I need to poll to check the status of my deployment? Would be nice to get information in the response body about the deployments status after having called the endpoint synchronous.

P.S. Keep up the good work, this feature/endpoint is awesome 💪

davidebbo commented 6 years ago

I wonder if this is the same root cause as #2272, which relates to error propagation in PowerShell scripts. You can try the workaround given by the users there to see if that works here.

nikolaia commented 6 years ago

I will test more thoroughly when I get the chance. Earlier I was messing up the access token, and 4xx codes made the script, and as a result the deploy in VSTS, fail. I guess that is why I assumed that the zipdeploy endpoint would fail my script when the deploy fails and throws during the Running deployment command...-step in Kudu. I tried reading the sourcecode, and got the impression that the zipdeploy endpoint returns 200 OK with no body even if the deployment fails, and was wondering if that was by design or should be improved?

davidebbo commented 6 years ago

@nikolaia I would not expect a 200 if there is a server side failure. Should be a 500 resulting from an Exception being thrown.

nikolaia commented 6 years ago

I made a pull request with some changes that shows what I think is a logical way for the API to respond to synchronous zipdeploys. Then I can fail easily in my VSTS script:

$response = Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=$bearerToken} -Method POST -InFile $zipPath -ContentType "multipart/form-data"
If ($response -eq "Succeeded") {
    Write-Host "Kudu responded 200 OK with body $response"
} else {
    Write-Error "Kudu responded 200 OK with body $response"
}
davidebbo commented 6 years ago

/cc @nickwalkmsft

JontyMC commented 5 years ago

We are seeing this issue. We get a 200 response back with no body when the deployment has actually failed.

This should be documented if not fixed, as the sync API is unusable in this state.

jvano commented 4 months ago

Hi

If the problem persists and is related to running it on Azure App Service, please open a support incident in Azure: https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

This way we can better track and assist you on this case

Thanks,

Joaquin Vano Azure App Service