0

Publish-AzWebApp throws an error when uploading the Source Code for the aplication. The code is the following:

    $job = Publish-AzWebApp `
        -WebApp $webApp `
        -ArchivePath (Join-Path -Path $rootPath -ChildPath $archiveRelativePath) `
        -Force `
        -AsJob
    # # #
    # ...code...
    # # #
    # Later on
    $job | Receive-Job -AutoRemoveJob -Wait -WriteJobInResults | ForEach-Object {
        if ("AzureLongRunningJob" -eq $_.GetType().BaseType.Name) {
            if ("Completed" -eq $_.JobStateInfo.State) {
                Write-Log -Message "Published the Source Code for $($webApp.Name) successfully." -Level INFO
            }
            else {
                Write-Log -Message $_.JobStateInfo -Level ERROR
                throw $_.JobStateInfo
            }
        }
    }

The error is the following:

Deployment failed with status code ServiceUnavailable
    + CategoryInfo          : InvalidResult: (:) [], Exception
    + FullyQualifiedErrorId :

The thing is that between the beginning of the job and the end of the job I am also uploading WebJobs and and also I'm setting the AppSettings from the Configuration Blade.

I also noticed that this happens when I am creating the app then doing this procedure in one go. But if the app exists, the error is less likely to occur. Still it doesn't seem like it is stable. What could I do?

Joy
  • 1,171
  • 9
  • 15
Garbem
  • 149
  • 1
  • 13
  • This could be a provisioning problem. Probably a wait time in between of creation of the WebApp and Publishing the code would help and also the fact that you do multiple deployments to the same app parallel is causing the issue. Changing them to sequential would probably fix the issue? – Repcak Oct 16 '20 at 13:05
  • So the steps are as follow: 1. create the webapp, 2. start a that publishes the source code, 3. meanwhile upload some WebJobs. The thing is that if you call Set-AzWeb app it works flawlessly, I do it to upload some settings to the webapp, right after it is created. The fact that Publish-AzWebApp doesn't handle this kind of issues, it makes it harder for me to figure out what I need to do. Also the documentation doesn't mention any preparation step... – Garbem Oct 16 '20 at 13:55
  • If these published jobs are separated and executed one by one, will an error message occur? – Jason Pan Oct 19 '20 at 05:21
  • Yes, the deployment of the WebJobs has no impact on the deployment of the Web Application Source Code via Publish-AzWebApp. Or at least, in my testing it had none. I am using: https://github.com/projectkudu/kudu/wiki/WebJobs-API anyway, which is not part of the Az.Websites so I believe it works with different API's. I might be wrong tho. – Garbem Oct 19 '20 at 07:49
  • If possible, you can send out the final answer to this problem to help more users, and you can also raise some precautions. – Jason Pan Oct 21 '20 at 06:53
  • But I found no answer. I junst answered your question. What am I doing now, is that I am retrying until I don't get the error. I don't have a quick solution and the main topic of the question is that I cannot use it with the -AsJob parameter reliably becasue it fails... – Garbem Oct 22 '20 at 07:40

0 Answers0