Is it possible to fail an Azure Release Pipeline stage if startup command is not successful? - azure-devops

I have an ASP.NET Core app and trying to automate deployment to a Linux-based Azure App Service through the on-premises Azure DevOps server. I managed to build everything and deploy the code to the App Service.
At this moment, the Startup Command which should run the application (dotnet dllname) fails. When I open the URL of my web app, I see the default Azure "welcome" page (served from opt/defaultsite).
I don't have a problem with this particular failure - I did not configure the connection string and other settings yet, so it was expected. However, I wonder how it is supposed to handle such failures. I have these concerns:
How do I know that the startup failed without visiting the web app manually? The Deploy task finishes successfully with a green mark despite the fact that the startup was not successful.
When the app fails to start, I would like to see the error message in the browser rather than the default site (at least for the non-prod environments). Otherwise, the only way to understand that I have a problem and see the reason is to go to the Kudu console and see the log stream.
If my app crashes, would it restart it or it will switch to the opt/defaultsite page again?
At this moment, to address the first concern, I am going to add another task to the Stage - a simple PowerShell script which would send a request to one of the app endpoints, however, I wonder if Microsoft suggests some better/more native solution.

Basically, the stage will be failed if there are errors/exceptions during the deployment.
However we cannot fail an Azure Release Pipeline stage if startup command is not successful, because the deployment is actually complete.
As a workaround you can add another task to run scripts to request the endpoints to detect that as you did.

Related

"Azure Web App Deploy" vs "Deploy Azure App Service"

If we are deploying a basic WebApp / WebApi, both these tasks from Microsoft appear to do the same thing - deploy to an appservice.
AzureWebAppV1
AzureRmWebAppDeploymentV4
How do you choose which one to use in a new YAML release pipeline? I just want to make sure I am using the version that is most future-proof - I have 25 release pipelines and don't want to have to re-do them unless necessary.
The way the help is written, hard to compare feature to feature to spot the key "must-haves". Some Microsoft online examples use both. Both are still marked as "In Development" in the readme and both are >1 year old since last check in.
The simplest way to deploy to an Azure Web App is to use the Azure Web App Deploy (AzureWebApp) task.
By default, your deployment happens to the root application in the Azure Web App. You can deploy to a specific virtual application by using the VirtualApplication property of the AzureRmWebAppDeployment task.
Azure App Service Deploy task allows users to modify configuration settings in configuration files (*.config files) inside web packages and XML parameters files (parameters.xml), based on the stage name specified.
Just my two cents, but I just noticed Web App Deploy takes much less time than Service App Deploy. I was wondering how come a simple zip deploy (Service App Deploy) can take so long. So I looked around and found there's also that Web App Deploy, so I tested it.
My project (React/Next small sized app) normally takes 6-10 min to deploy with Azure Service App Deploy (v4). With Azure Web App Deploy (v1) it took a little more than a minute. Wow.

Web Deployment runs with error, but does nothing

I'm running a CI pipeline on Azure DevOps. Part of the release pipeline is deploying a website to our web server (running IIS).
We changed hardware recently and did a fresh install of Windows. Of course I also installed the WebDeploy handlers and everything. But since then, the deployment runs without error, but it doesn't actually update any files. If I publish the website from VS2019, everything is fine.
How would I troubleshoot this?
I forgot to include the new server into the deployment group. Only noticed it when we finally turned off the old server and got the error message that the target was offline.

Failed to deploy web package to IIS website. By the Self-hosted Windows agent

Failed to deploy web package to IIS website
I have created one ASP.NET Core application and Azure DevOps continuous integration (CI) and continuous delivery (CD) pipeline.
I have created and configure the Self-hosted Windows agents in my local machine as a service. It is working as expected.
When I run the CI/CD pipeline for the first time it is working successfully, and the web application published to my local IIS successfully.
The issue is when I commit another update to Azure DevOps git repository it is failed to deploy web package to my local IIS website with the following errors and warnings
2019-08-21T10:56:59.1480862Z ##[error]Failed to deploy web package to IIS website.
2019-08-21T10:56:59.1492670Z ##[warning]Can\'t find loc string for key: Trytodeploywebappagainwithrenamefileoptionselected
2019-08-21T10:56:59.1493093Z ##[warning]Trytodeploywebappagainwithrenamefileoptionselected
2019-08-21T10:56:59.1493421Z ##[error]Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'DemoWebApp.dll' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.
Error count: 1.
I have configured the appOffline rule in the publishing profile (.pubxml) and add the EnableMSDeployAppOffline element to the PropertyGroup like this:
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>
As described in More Information’s learn more URL http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.
Still it is failed to deploy web package to my local IIS website with the same errors and warnings.
When I trying to redeploy manually few times then it is working successfully other wise failed with same errors and warnings. Because I think the file is locked for some time in my local machine process.
It is also working successfully when I manually delete all the files from IIS release folder with that locked file.
Needs help, the file is locked by any one local process. I couldn’t find that local process. I couldn’t figure out the issue. I also don’t know if I found that process any how then how to figure out the issue. Is this just local issue?
Can anyone help me out?
Recycle the application pool immediately before your 'Deploy IIS App' task.
Add a 'WinRM - IIS Web App Management' task to you release pipeline. Set the Configuration type to 'IIS Application Pool', set the 'Action' to Recycle, and type in the app pool name in the 'Application pool name' field.
The recycle should unlock the dll and allow it to be deleted and replaced in the deployment step.
I encountered this same error despite having the Take App Offline option set for ages. That can't be the solution. There's some phantom bug going on here, but I did get it resolved without rebooting the server.
In PROCMON, I searched Associated Handles for the file in use. There were none.
I tried deleting the app's DLL file outright; an error message said it was in use by w3wp.exe even though the website was offline and the app pool stopped.
I confirmed this by opening IIS and looking at the worker processes panel. None of the active w3wp.exe PIDs were related to the application I was trying to update.
I opened PROCMON and sorted by Image name to find any W3WP.exe instances still running. There was one Suspended instance that it wouldn't let me terminate (despite running PROCMON as an admin/with elevation). It simply said "Access is denied."
I restarted the Agent on the server via the Services window.
At that point, I was able to delete the application DLL from the target directory and deploy normally from DevOps pipelines.
Hopefully this doesn't happen in production.
I had the same error .
I splved by checking the "enable IIS" to my task , like this :
Now my lob suuccseded
I was deploying my web app on local iis using IIS Web App Deploy task.I was able to reproduce the same error. I found this error occurred if i was visiting my website when i was trying to deploy a new version. And the deploy task failed to update the .dll file, since it was in use.
I fixed this error by checking this option “Take App Offline”, See below pic.
Please let me know If you are using different tasks to deploy your web app.

Getting ERROR_FILE_IN_USE while using Web Deploy in Azure App Service Task v3

Similar questions have been asked various times, but most answers are old and may only partially apply. This question is specific to using Web Deploy through Azure DevOps/Azure Pipelines using the "Azure App Service Deploy" task, version 3.*.
Failed to deploy web package to App Service.
Try to deploy app service again with Rename locked files option selected.
Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'VBCSCompiler.exe' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish
attempt. Learn more at:
http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.
There's two recommendations there:
Select "Rename locked files" option
Restart the application
Use the AppOffline rule
Additionally, the documentation for the task reiterates recommendations 1 and 3 together.
For avoiding deployment failure with error code ERROR_FILE_IN_USE, in case of .NET apps targeting Web App on Windows, ensure that 'Rename locked files' and 'Take App Offline' are enabled. For zero downtime deployment use slot swap.
However, these recommendations are already in place.
All that's left is recommendation 2: restart the service. For many reasons, I rather not have to fall back to this.
Why are 1 and 3 not enough to complete the deployment successfully?
I spoke with a Microsoft support rep and was told that "Rename locked files" only works for DLLs.
But I did find a solution that did work for me. In "Additional arguments", I added "-useChecksum". So the "Deploy Azure App Service" task now looks like this
I haven't had any problems since.
There is an issue tracked here : Azure App Service Deploy fails for .net core 2.0 with ERROR_FILE_IN_USE and based on vincentdass's comment "PR #8457 for consuming new version of MSDeploy as per Web Deploy team recommendation." There will be an upgrade for msdeploy in future version.
However you can just checking Publish Using Web Deploy and Rename Locked Files, then creating a new deployment. Redeploy won't work because it won't pick up your changes to the release definition.
Reference below thread, you can check the discussion about this issue and troubleshoot accordingly.
Azure App Service Deploy fails for .net core 2.0 with
ERROR_FILE_IN_USE

How to write a powershell script to release file if used by any other process

I am using octopus deployment with teamcity. In many cases deployment fails because "The process cannot access the file or dll because it is being used by another process. How to write a script to fix this problem. Please guide.
I'm reading into your question a little here, but it sounds to me that you're trying to deploy a website and it's failing, because the IIS worker process is using the files - what you want to do is recycle the application pool of the website before you deploy, or, if it's a high traffic website, stop the website, do the deploy, then start the website.