Search code examples
azureazure-webjobsazure-powershell

How to automatically deploy a web job to Azure portal using Power shell


I have been checking for ways to deploy a web job to azure automatically using PowerShell. I saw some blogs that depict the steps and the following summarizes what I have tried

  1. I build my application (ASP.NET Console Application) in release mode and Zipped the contents of bin/Release to a folder.

  2. In PowerShell, I logged in with az login

  3. Then I tried the following commmand

    Invoke-WebRequest -Uri https://$applicationName.scm.azurewebsites.net/site/wwwroot/app_data/jobs/triggered/$webJobName ` -InFile $ZipFile -ContentType "application/zip" -Method Put

$ZipFile has the path to the folder I created on step 1.

The output I get is the following

Invoke-WebRequest : The page was not displayed because the request entity is too large

Please let me know if you know what the issue is or If you have any reference that would help.

Thanks in advance!


Solution

  • Thanks for pitching in everyone! Your input was helpful, however I would like to update the answer with the solution I found that was so easy and saved me so much time. I will like to update you on how I could successfully deploy the app service and web job in a single go. Its very easy and since it deploys web app and corresponding web jobs in a single go, this was the perfect solution for my scenario. Thanks to my colleague who helped me with this solution. The following depicts the steps I had to go through.

    Lets suppose that my app service in Azure is "appService1" and I want to create a triggered web job under appService1 that goes by the name "webJob1". I followed zip-deployment with azure cli.

    1. Publish your web application (For the app service) solution in release mode to get the files you will have to deploy. Let this folder be WebAppBuild.
    2. Build your application (a console application in my case) that would serve as the web job for the app service in release mode.
    3. Inside the published folder for the web application (for app service ie WebAppBuild in our example), add a folder with the following path

    app_data\jobs\triggered\webJob1

    (If you need more than one web jobs deployed, you can create more than one folders like webJob2, webJob3 etc)

    Add the files you have in step 2 to this folder. This is basically the files needed for your web job

    1. Zip the contents in a single folder that acts as your deployment folder for web app and web job
    2. Go to powershell and run az login (works if you have installed azure cli, otherwise you will have to install it as well)
    3. Log into your respective account with the prompt window
    4. Run the following commands that sets run from package property to true for your web app and the second command is the actual deployment command
    az webapp config appsettings set --resource-group <<resourceGroupName>> --name <<appServiceName>> --settings WEBSITE_RUN_FROM_PACKAGE="1" ; 
    az webapp deployment source config-zip --resource-group <<resourceGroupName>> --name <<appServiceName>> --src <<zipFilePath>>
    
    
    1. Now login to your azure portal and navigate to your web app. Check under web jobs option and you will see that the web job has been created with the files you deployed.

    For more help on starting, stopping, deleting the web job with azure cli, go through the following document. Check here