How do I get a web job to use the azure portal storage connection string, not what's in the web job console app's deployed config file? - azure

I've created a web job using the webjobs sdk that is linked to my web application. Well it isn't anymore (I removed the webjobs-list.json file from the web app project), because when it was linked, it just copied the source code files into the websites' app-data folder, not the bin folder/binaries/exe. But now that my web job is deployed from visual studio online to azure with my website, and tries to run, it's not reading the connection strings (AzureWebJobsStorage and AzureWebJobsDashboard) from the connection strings in my web application's settings in the azure portal. It looks for them in the config file that is deployed with the exe that is generated from compiling the webjob. If I manually put those strings in that config and check in, and redploy it will use them from there, so it's not checking the portal at all (even though my web app is running fine using what is defined in the portal). I thought that all web jobs were supposed to look for connection strings in the azure portal first? That isn't happening at all for me. Has anyone else experienced this? Could it have something to do with how it's deployed by visual studio online?
Part of the error getting logged for the webjob process when trying to start:
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Functions.ProcessTestQueueMessage' ---> System.InvalidOperationException: Microsoft Azure WebJobs SDK 'Storage' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:
[04/01/2017 02:27:40 > ceef22: INFO] 1. Set the connection string named 'AzureWebJobsStorage' in the connectionStrings section of the .config file in the following format , or
[04/01/2017 02:27:40 > ceef22: INFO] 2. Set the environment variable named 'AzureWebJobsStorage', or
[04/01/2017 02:27:40 > ceef22: INFO] 3. Set corresponding property of JobHostConfiguration.
[04/01/2017 02:27:40 > ceef22: INFO] at Microsoft.Azure.WebJobs.Host.Executors.StorageAccountParser.ParseAccount(String connectionString, String connectionStringName, IServiceProvider services)
Also, the only way I could get this to really deploy was to remove the webjobs-list.json file from the properties folder in the web project. I know I'm not supposed to do that, that everything should just work and deploy with that in there, but when I left it in there, it wouldn't copy the binaries/bin/executable files into the App_Data\Jobs\continuous[webjob] folder on the website...it would literally copy all of the source code\files for the web job project into there (which of course wouldn't work/run, since it's just code, not an exe). After removing that webjobs-list.json file, and then adding a second task to my release to find the [webjob].zip file from the build, then it would copy just the binaries and executable into the App_Data\Jobs\continuous[webjob] folder. Maybe this is just an issue with trying to build and release from visual studio online, and it doesn't handle web job deployment well...not sure, I haven't been able to find a lot of information on setting that up to deploy a web job with a web app.

Normally, this should just work. The flow is:
The WebJobs exe doesn't run in-place, but first gets copied to a temp folder
As part of that copying process, if any of the AppSettings & Conn Strings in the foo.exe.config file are set as Azure settings, they get replaced (only in the temp copy, not under App_Data).
Can you make sure that you are deploying both your foo.exe and foo.exe.config?
Update: as we found on chat, the problem was that you had a typo in the name of the connection string in Azure.

Related

Azure App Service Could not load file or assembly

I am trying to stand up a sitecore site inside a fresh app service in Azure. This already works in our production Azure account, but we would like to see how to set it up from scratch.
The build and deploy succeed in pushing it out to the app service, however, I am getting:
Could not load file or assembly 'System.Web.Http.Cors, Version=5.2.3.0
and no further information. I verified that system.web.http.dll is present in the bin folder. I read in some other articles that sometimes the wrong version could cause issues but this works on my work machine. Is there another step I need to do to make this work in an app service? Some configuration change, maybe?
The dll is missing in the published (deployed environment). That is the reason why it is working in the local i.e. Visual Studio but not in the Azure Website Environment.
Just do Copy Local = true in the properties for the assembly(System.Web.Http.Cors) and then do a redeploy, it should work fine.
If Copy Local is already set to true and you cannot update the WebApi because of dependencies, there is that trick to set Copy Local to false, build, then set Copy Local back to true and build.

Azure - Web deployment task failed. An error was encountered when processing operation 'Delete Directory' on (Application Insights)

I'm using Right-Click publish in Visual Studio to publish directly to my staging slot in Azure. I've added Application Insights that added a WebJob to my app.
I have enabled Remove additional files at destination and Precompile during Publishing turned on.
But when a Web Job is running and my staging site is not 'stopped', because it's still warmed up - I get the following error:
Web deployment task failed. ((18-Jan-18 22:47:23) An error occurred
when the request was processed on the remote computer.)
(18-Jan-18 22:47:23) An error occurred when the request was processed
on the remote computer. An error was encountered when processing
operation 'Delete Directory' on
'D:\home\site\wwwroot\App_Data\jobs\continuous'. The error code was
0x80070091. The directory is not empty.
at
Microsoft.Web.Deployment.NativeMethods.RaiseIOExceptionFromErrorCode(Win32ErrorCode
errorCode, String maybeFullPath) at
Microsoft.Web.Deployment.DirectoryEx.Delete(String path) at
Microsoft.Web.Deployment.DirPathProviderBase.Delete(Boolean
whatIf) ProjectX.Web 7 0
I can fix this by manually stopping the staging slot, upload it, and then start it again. This is quite cumbersome though.
Is there a fix?
I read somewhere that you can automatically take the (staging) app offline during publish but I can't find the setting.
UPDATE 1
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>
...is not working for me.
UPDATE 2
Adding the WEBJOBS_STOPPED setting on the Staging slot is not working for me.
As you have enabled Application Insights on your Azure App Service, it has internally installed an extension which started a continuous web job and content corresponding to web job got copied to App_Data folder. The actual problem is because extension data get copied to App_Data folder where only user's data should reside instead of infrastructure data.
Now when you are selecting the option "Remove Additional Files From Destination" in visual studio, it tries to remove all contents including Application Insights data from App_Data folder. Since Application Insights web job is already running in background hence corresponding dll files are locked.
Even if you go with option of "App Offline" or "Stop web job" and successfully able to delete all contents then your deployment will succeed but this way your Application Insights will get corrupted and hence you may have to configure Application Insights again.
Suggestion:
Select skip "App_Data" folder along with option "Remove Additional Files From Destination".
It will delete all content except App_Data folder content and hence dll files corresponding to Application Insights continuous web job will be skipped.
Reference :
VSTS - Azure App Service Task Documentation
Limitation
Though this solution have a limitation - If you want to remove/modify existing user defined web jobs then can't skip App_Data folder. In such case either have to perform two step deployment or have to reinstall application insight extension again.
I found this in another SO question:
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
...
</PropertyGroup>
... adding to your publishing profile (.pubxml).
The full answer is here: https://stackoverflow.com/a/20888597/647845
UPDATE
This is not working for me. Maybe for others. Seems to ignore the setting.

Azure WebJob deployment keeps failing

Since yesterday I'm suddenly having consistent deployment failures for my existing WebJobs. The error I'm getting is
Start Web Deploy Publish the Application/package to https://octotrip-api-test-dev.scm.azurewebsites.net/msdeploy.axd?site=octotrip-api-test__dev ...
Adding sitemanifest (sitemanifest).
Adding directory (XXX\app_data).
Adding directory (XXX\app_data\jobs).
Adding directory (XXX\app_data\jobs\continuous).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4295,5): Error : Web deployment task failed. ((3/16/2017 1:32:23 PM) An error occurred when the request was processed on the remote computer.)
(3/16/2017 1:32:23 PM) An error occurred when the request was processed on the remote computer.
An error was encountered when processing operation 'Create Directory' on 'D:\home\site\wwwroot\app_data\jobs\continuous'.
The error code was 0x800700B7.
Cannot create "D:\home\site\wwwroot\app_data\jobs\continuous" because a file or directory with the same name already exists.
at Microsoft.Web.Deployment.NativeMethods.RaiseIOExceptionFromErrorCode(Win32ErrorCode errorCode, String maybeFullPath)
at Microsoft.Web.Deployment.DirectoryEx.CreateDirectory(String path)
at Microsoft.Web.Deployment.DirPathProviderBase.CreateDirectory(String fullPath, DeploymentObject source)
at Microsoft.Web.Deployment.DirPathProviderBase.Add(DeploymentObject source, Boolean whatIf)
Publish failed to deploy.
Important to note that at the time of the deployment; there is no app_data folder (I removed it manually using FTP). You can see it is creating the folder structure step by step; app_data, then the jobs folder, then the continuous folder. I confirmed using FTP that he succesfully creates the app_data/jobs folder; but creating the continuous folder consistently crashes.
This happens when deploying using a build definition in VSTS as well as deploying as a WebJob from within Visual Studio; with all the WebJob NuGet up to date.
Thanks
It is very odd that can't create folder for WebJob. I can't repro it in my side. Do you have a try to deploy it to another website to check whether it can be repro?
Based on my experience, we could troubleshoot with following ways:
Restart the Website
If it is possible try to redeploy the Website and remove additional files at destination
Scale up and scale down back Service plan
Note:change will be applied to all WebApps in the ServicePlan
Please contact Azure Support team for help if it is not resolved .
Worked around the issue by simply creating a new Azure Web App. Something messed up going on with the file system. Take a look.
app_data or subdirectories of app_data don't exist on the server. (confirmed using CMD and FTP).
This only happens for
app_data\jobs\triggered and
app_data\jobs\continuous
(app_data\jobs\triggereddddd works for example)
These folders have existed on this server before (they contain the data for the WebJobs that we're running)
open Azure Portal and go to your web app
Under "development tools" select "K Advanced Tools" this will open the Kudu control panel in a new browser window.
Select "Debug Console" -> "CMD"
in the Items table, locate the wwwroot entry and delete it.
continue working ...

VSO not deploying Azure website with WebJob

A website with webjob not deploying to Azure.
I am having an issue getting a website with an associated webjob console application to deploy using continuous deployment via Visual Studio Online. I am using VS2013 with update 4 and latest Azure SDK.
The website, and the associated webjob, will publish to Azure using direct publish for Visual Studio and works perfectly, so I am confident the publish settings are fine.
The solution will build and work locally fine.
The solution, once checked in, will build and (seemingly) deploy fine in VSO (using CI) and Azure notes the build was successful and shows it as 'Active deployment'.
However, the website and associated webjob will not be updated.
When I have browsed the deployed files after the VSO build and deploy on Azure, all that is happening, is the binaries of the console app are being copied into the bin/ folder of the website.
None of the website files are being updated. It is almost as if it is deploying the wrong project!
If I remove the Webjob and just deploy the website, it will build and deploy fine through VSO - the website will update.
It is adding the webjob that causes some issue with the deployment via VSO.
I am confident all steps are correct to add the webjob to the WebApp, with the correct webjobs-list.json being added to the webapp and webjob-publish-settings.json to the Console app - as I said, publishing the website (with the webjob) direct to Azure works perfectly, and both the site and webjob get updated.
I have searched post after post and tried all manner of things, but none have worked.
Given the fact this published fine direct from VS, and also that the build is completing, it would suggest that something is wrong with the VSO Build Defintion.
My first guess would be to change it from building the solution to instead building the web project only, but this does not seem to work.
I have also tried every Output location setting (both for the solution build and the web project build) - the only one that works and the build completes is the solution (.sln) build with 'SingleFolder' set.
I have been battling this for a couple of days now an I'm a bit stumped!
This also happens if you have a static website being deployed using a Visual Studio solution via VSO with an automated build - unless the Visual Studio project / solution containing the website is changed then the actual site contents will not be redeployed.
I think your hunch that it's deploying the wrong project is correct. If you have multiple "deployable" projects in your solution (and the console app is considered deployable, as this is one way you can host/deploy a webjob), you need to tell Kudu which one to deploy.
You can control it adding a new setting under "app settings" on the "configure" tab for the webapp.
The setting you want is Project and it's a relative path from the solution root to the .csproj file of your web project.
Alternatively, you can specify the setting in a custom .deployment file.
Relevant Kudu documentation here
From the documentation:
You can specify the full path to the project file. Note that this is not a path to the solution file (.sln), but to the project file (.csproj/.vbproj). The reason for this is that Kudu only builds the minimal dependency tree for this project, and avoids building unrelated projects in the solution that are not needed by the web project.
Here is an example:
[config]
project = WebProject/WebProject.csproj
I have also tried every Output location setting (both for the solution build and the web project build) - the only one that works and the build completes is the solution (.sln) build with 'SingleFolder' set
That's the root case of problem.
You can't have SingleFolder as it sets the OutDir which mess up with web job packaging.
I had to introduce a wpp.targets files in each of my web app project to create the publish package to a particular path (using PackageLocation)
So, let each project have that and set the setting to AsConfigured (or Per Project) instead of SingleFolder.
See this

Error Deploying New Relic Instrumented Site to Azure from Github & VS.NET

I am getting the following error:
Error: The process cannot access the file 'C:\DWASFiles\Sites\mywebsitename\VirtualDirectory0\site\wwwroot\newrelic\NewRelic.Agent.Core.dll' because it is being used by another process.
In the Running deployment command... log file when attempting to deploy an Azure website from Github.
Would appreciate any pointers as to what could be causing this.
UPDATE: Turns out this is also failing when publishing directly from VS.NET with the following:
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4196,5): Warning : An error was encountered when processing operation 'Create File' on 'NewRelic.Agent.Core.dll'.
1>Retrying operation 'Update' on object filePath (mywebsitename\newrelic\NewRelic.Agent.Core.dll). Attempt 1 of 2.
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4196,5): Error : Web deployment task failed. ((06/07/2013 23:54:58) An error occurred when the request was processed on the remote computer.)
This was working before and I am not sure why it would have stopped.
NewRelic recommend stopping the website to unload the file and allow the deployment to go through.
As an alternative, you can set COR_ENABLE_PROFILING to 0 in your app settings on the configure tab to temporarily disable the profiling, which should then allow you to continue with the deployment while leaving the website operational throughout.
Instead of stopping the website you can temporarily turn off New Relic monitoring via the Configure tab on manage.windowsazure.com:
Configure > developer analytics > select "OFF" > Save
Deploy
Configure > developer analytics > select "ADD-ON" > Choose Add-on from dropdown > Save
Worked for me, both with a regular deployment from VS and an automatic build from VSO.
This is a known issue with the New Relic .NET agent for Azure Websites when performing an upgrade of the agent. The workaround is to stop the website to release the dll, finish the deployment and then restart the instance.
https://newrelic.com/docs/dotnet/azure-web-sites#h2-1
Not really a solution but more of a work-around, in the publish dialog view a preview of the changes and uncheck the NewRelic.Agent.Core.dll file so that it doesn't get published.
None of these answers work for me anymore. I have an Azure Basic tier website plan, which hosts multiple actual websites.
If I don't stop the website, I get the error mentioned above (newrelic.agent.core.dll is in use)...
If I do stop the website (or all of them), I get an error saying that the publishing endpoint isn't available.
If I go to the configure tab and disable the AddOn, we still get the error mentioned above (newrelic.agent.core.dll is in use)...
Pretty much we just republish over and over again with different permutations of the above until if works. It took me hours the other day, took me 10 minutes today.
If you are using webdeploy, then you can configure your webdeploy settings so that it ignores the file. However, if you do that, you will manually have to deploy any updates to the new relic agent.
I had a similar issue with the new relic log file being locked, and solved it by:
Moving the new relic log file to a subdirectory of the web root (e.g. \newreliclogs)
Adding 2 lines to my powershell script that configured the skip directive to ignore that whole directory. e.g. (where destBaseOptions is of type Microsoft.Web.Deployment.DeploymentBaseOptions
$skipDirective = new-object Microsoft.Web.Deployment.DeploymentSkipDirective("NewRelicLog","objectName=dirPath,absolutePath=.*\newreliclogs$")
$destBaseOptions.SkipDirectives.Add($skipDirective)
Depending on how you are using webdeploy, the configuration is achieved slightly differently, I used the following links to help me piece it together:
https://technet.microsoft.com/en-us/library/dd569089(WS.10).aspx
https://msdn.microsoft.com/en-us/library/microsoft.web.deployment.deploymentskipdirective(v=vs.90).aspx
https://msdn.microsoft.com/en-us/library/dd543313(v=vs.90).aspx
http://blogs.iis.net/jamescoo/archive/2009/11/03/msdeploy-api-scenarios.aspx
http://forums.iis.net/p/1192163/2031814.aspx#2031813
And I used the powershell script from the Octopus Deploy Library at https://library.octopusdeploy.com/#!/step-template/actiontemplate-web-deploy-publish-website-(msdeploy).

Resources