Executing a Bat file on Azure remotely - azure

Currently I have a Play application that is being deployed to azure with FTP. After the deploy is successful I need to execute a bat file "run_app.bat" to start my play application on my azure website.
The build is running on Gitlab, and the file on Azure is located in the wwwroot directory.
Is there anyway I can add a command to my gitlab build that will execute this file? Im trying to automate the deployment process.
Note: Im really green with matters such as this, azure and devops
I tried finding a way to connect to Azure using the azure cli but I was unable to discover any commands that were suited to my needs. Read a bit about WebJobs but failed to understand how they work or how to set them.
Tried seeing if the Kudu console was accessible from a command line but got negative feedback on that.

You could run your batch file with Kudu Debug Console. Just execute .bat file in the CMD console.
And about deployment with custom scripts you could refer to this wiki and blog. And there is a link in the wiki, it shows the detailed the steps to set the Customizing deployments.
If you still have other questions, please let me know.

Related

Dotnet-counters output from Azure App Services

I'm trying to find a way to get dotnet-counters output from Azure App Services to either the Azure Portal (good enough for some trouble shooting) or some other console tool.
Does anyone know of a way to get the data, even when the app service is running across multiple app service plans? I was picturing maybe there is an app service extension (but no luck so far).
Eventually I'll want to automate this so I can get the data onto our monitoring system, but first baby steps.... just need something I can manually eyeball to help debug issues.
Anyone have any thoughts on how to do this?
Thanks
Ken
From offical doc, we can install dotnet-counters by cli command and download .exe directly.
As azure web app running in sandbox environment, so we can't add dotnet-counters to env, which means we can install it, but we can't use it.
So my solution is,
we can download .exe file directly.
After downloading finished, we can copy and paste it to wwwroot.
Then we can use it on scm site and azure portal.
On kudu site.
On azure portal.

Getting error "Request to a downlevel service failed" when deploying to Azure

As of today I have begun getting the following error when I try to deploy our ASP.NET web services to our Azure web hosting from Team Foundation Services 2015.
Getting down to the details of the error message we have the following.
It generates warnings when executing the Get-AzureWebsite script then generates an error when executing the New-AzureWebsite script.
This has been working for several years without a problem but as of today it is now generating an error. I am unable to deploy our latest code changes because of this error.
UPDATE
After some investigation it appears as if the Azure scripts that are used to underpin the TFS tasks have all been deprecated. Which therefore begs the question, what is the migration path for those deploying to Azure using TFS 2015? Is there a new TFS task which will use the new scripts instead? How do I update my TFS deployment so that it doesn't generate this error?
UPDATE2
I have installed the latest PowerShell and installed the Azure RM Automation cmdlets. I have updated the script Publish-AzureWebDeployment.ps1 to use Get-AzureRmWebApp instead of Get-AzureWebSite and New-AzureRmWebApp instead of New-AzureWebSite but I'm still getting errors.
Have Microsoft provided any updates to TFS or the underlying Azure deployment scripts since deprecating the old Azure scripts? Surely Microsoft aren't expecting the developers to re-write these scripts ourselves?
My solution to the my problem was a workaround. Instead of deploying my application to our Azure hosting using an Azure Web App Deployment task, I have created an FTP script that does this. I am using WinSCP as this can be run from the command line and has the ability to easily synchronise your local and remote directories without to write any complex FTP commands. It does this
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script=ftpDeployServices.ftp
And here's the FTP script ftpDeployServices.ftp.
option batch abort
option confirm off
option transfer binary
open ftp://myusername:mydomain.ftp.azurewebsites.windows.net/site/wwwroot
cd /site/wwwroot
synchronize remote -delete "C:\DEV" /site/wwwroot
close
exit

Upload custom exe to Azure Devops pipeline

I'd like to execute a command line app that I created as part of my CI builds.
The command line app is not related to the repository on which the build is running. (Basically, its a tool that is supposed to send some project related metadata to a company web application to gather some metrics).
It seems I can execute it using a Command Line task, as explained here:
How to execute exe in VSTS Release pipeline empty process
The question is, however - how do I upload my custom tool into Azure Devops?
I know it's possible to create custom tasks (https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops) , but it seems quite a lot of effort to create, especially given that I have a console tool that is doing what I need.
I do this by including a seperate deployment folder in the git repo with my source code. This folder contains all the extra stuff (exe's) that I need to call to deploy.
You could if you wanted keep these artifacts in a different repo and/or different artifact if you wish as you can get any number of different artifacts
Then I include the deployment folder when publishing artifacts. In your build step you pull down the artifacts and it includes your EXE.
You're meant to be able to use things like NPM to install helper libraries on the fly but none of my required libraries were ever supported.
You can also use a self hosted agent which is your own host (Often an Azure VM). You install everything you need on there then you install a DevOps self hosted agent which lets build pipelines use it.
Create a build of your exe
Upload your exe to blob storage.
Create a SAS token to access your blob.
In your build create a task with a PowerShell script. In the PS script download your exe (unzip), and copy it to Build.StagingDirectory/"yourToolFolder". Then in your PS script run it. You probably want to pass it arguments like the location of the repo on the build agent.
A way to achieve this involve create a deployment group and add a server to the group where you have access and privileges to upload your console. it could be onprem or cloud depends in your requirements.

Azure Devops - How to run a powershell script on an App Service post-deploy?

I'm struggling to understand how to run a powershell script (it just runs an exe) on the App Service after deployment using Azure Devops.
FYI - the exe just reads some config info in the web.config and does some database updates. So it needs access to the transformed web.config and the SQL Server database that the App Service has.
I've tried adding a Powershell step using a Release Pipeline deployment task, but it seems to only run on the Agent, which does not have the context that the exe needs.
I can run the script manually using the Kudu command line window tool, but I need to automate this thing.
I've seen a few SO articles like this: How to add a custom post deployment script to azure websites? or Kudu post-deployment commands not running but I think that only works when you use the inbuilt deployment mechanism for App Services. ie - I couldn't get it to trigger the script in post-deploy from Azure Devops.
This is in the comments above, but if people find it useful, the answer to this is
Using the Azure App Service Deploy task, expand Post Deployment Action, there's an option to run a script (or inline write one).
This will be executed as part of the app service deployment and should allow you to do what you want. It's run at the wwwroot folder so the files need to be present in your actual deployment (zip/folder).

FTP'ing a Suave app to Azure

Having never used Azure before I'm attempting to deploy a simple F# Suave app to Azure using FTP. Ultimately I want to deploy via github but I initially thought FTP'ing it would be the easy first step. According to https://suave.io/azure-app-service.html it should be straight forward.
These are the steps I followed
Created a new web app in Azure including a resource group
and app service plan. All on the Free Tier.
Downloaded the publishsettings XML file that Azure created.
Cloned this repo: https://github.com/isaacabraham/fsharp-demonstrator
Used FileZilla to connect via FTP using the creds
from step 2.
Uploaded the files (via FTP) from
fsharp-demonstrator/src/SuaveHost (which includes the necessary web.config file) from the repo cloned at step 3 to
the site\wwwroot on Azure.
Navigated to Azure site url.
Then I receive the error:
The specified CGI application encountered an error and the server terminated the process.
(When I look at the folders on Azure under site\wwwroot I don't see any obj or bin folders. I don't think any msbuild process occurred. That doesn't seem right.)
Anybody got any idea what the problem is?
I suspect the issue is that when you deploy via FTP, then Azure does not automatically run the deploy script specified in the .deployment file.
The build.fsx script uses Kudu service to deploy the built files, so it might be easier to just use Github deployment rather than FTP - this way, Azure will do the deployment for you.
If you want to deploy via FTP, you'll need to build the project locally and upload the output. I'm not sure how to best do this with Isaac's Kudu-based demo though (ultimately, you need web.config that points to your built executable like this)

Resources