Search code examples
asp.netazureazure-web-app-serviceazure-webjobsazure-webjobssdk

How do I add a webjob to my aspnet appservice using only the CLI


I am working on macOS with an external text editor (NOT VisualStudio). I have an asp.net project that I push to my app service using

git push azure main:master the remote is configured as such https://$name:[email protected]:443/name.git

when I go to the web jobs section in the app service to add a web job, I get the error message:

enter image description here

I want to continue using my source control push method while developing... however I would also like to add a csharp console webjob . I have followed the tutorial here (A) https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started, and have a functoining console app that consumes a message from a queue.

How can I push this extra console app to my Kudu instance? I read here that there is a 'hidden' structure not in the main doucmentation (A) I linked above for the tutorial: https://github.com/projectkudu/kudu/wiki/WebJobs.

Do I have to manually zip the result of dotnet publish -c Release to some Kudu folder? Or is there a more elegant way by somehow including this project inside my git repo that I push normally... or using an az cli tool to push the webjob to the app?


Solution

  • Found a way to push directly using az cli

     az webapp deploy --name $APP_NAME -g $RG \
                      --src-path program.py \
                      --type static \
                      --target-path /home/site/Jobs/continuous/Job$RANDOM/program.py
    

    for larger programs in .net I just dumped the project on Kudu, unzipped, and rebuilt (I'm on a mac m1 so can't build against x64 without some hoops, this was easier workaround)

     # on my machine
     az webapp deploy --name $APP_NAME -g $RG \
                      --src-path path_to_dotnet_project.zip \
                      --type static \
                      --target-path /home/site/Jobs/continuous/Job5/myproject.zip
    

    then on the app service (using kudu cmd/powershell)

    cd /home/site/Jobs/continuous/Job5
    unzip myproject.zip
    dotnet build -c Release
    cp bin/release/net6.0/* /home/site/Jobs/continuous/MyNewJob
    #job in MyNewJob automatically starts since this is in the 'continuous' folder