1
votes

I am publishing my console application as an Azure WebJob. I would like to run the webjob every day at 0.30 am. But just for testing, I am trying currently with every 5 minutes. Which works fine. But I also want to use an argument, which is passing to the arg[0] to my static void Main(string[] args) method.

My Web Deploy.pubxml

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <ADUsesOwinOrOpenIdConnect>False</ADUsesOwinOrOpenIdConnect>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://testProjectHello.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <MSDeployServiceURL>testProjectHello.scm.azurewebsites.net:443</MSDeployServiceURL>
    <DeployIisAppPath>testProjectHello</DeployIisAppPath>
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <UserName>$testProjectHello</UserName>
    <_SavePWD>True</_SavePWD>
    <_DestinationType>AzureWebSite</_DestinationType>
  </PropertyGroup>
</Project>

webjob-publish-settings.json:

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "webjobNameTest",
  "runMode": "OnDemand"
}

My settings.job file:

{
  "schedule": "0 */5 * * * *"
}

In the azure portal I see the following:

NAME TYPE STATUS SCHEDULE

webJobNameTest Triggered Ready 0 */5 * * * *

How can I pass an argument in my web job? Is it also possible to deploy multiple azure web jobs with different parameters from one console application? So I can run the webjob every day, and every week and every month. Including a parameter so my logic knows whether to get the day, week or month data.

1
Have you looked at this question? stackoverflow.com/questions/35362847/…Eric Petroelje
In that way, it looks like I have to create a console app and deploy it for each variable. I've also seen that it's possible to get the webjob name via the WEBJOBS_NAME environment variable. In that way I don't need to create a new console app, but I will have to change the logic. I hope there's a way to just deploy 3 web jobs with 3 different parameters with just one single click.1408786user
Yup, I see what you are saying. Maybe try this suggestion? stackoverflow.com/questions/25735831/…Eric Petroelje

1 Answers

0
votes

Posting as an answer because I do not qualify for comments. This is what worked for me.

Step 1 - Create a new subfolder under %HOME%* folder where your custom console exe will reside

  • Browse to Azure portal.
  • Create a new Web App under Service App
  • From the Tools menu under your Service App, launch Kudu web site
  • On the Kudu web site, click on Debug Console --> CMD

e.g. In my case, I created a subfolder Tool under d:\Home and uploaded MyConsole.exe and accompanying files like DLLs and MyConsole.exe.config to d:\Home\Tool

Step 2 - Create a BAT file to launch your custom console EXE

I created a .BAT file on my local disk, say Launcher.bat. This BAT file has only 1 line

d:\Home\Tool\MyConsole.exe arg1  arg2

Step 3 - Create a scheduled Web job using the BAT file

  • Browse to Azure portal.
  • Select your Web app from App Services
  • Select Web job

Create a scheduled web job. Upload the file Launcher.BAT file that you created in your earlier step. Configure schedule and create the job.

Caveats

  1. You will need to create a new .BAT file for every instance of command line argument
  2. However you do not need to duplicate the binaries

Hope this helps.