Azure – Connect to Key Vault from .Net Core application using Managed Identity – Part 3 – Publishing / Deploying .Net core console application as a Azure WebJob and Schedule it

Hi All,

LIFE IS BEAUTIFUL 🙂 I hope we all are safe:) STAY SAFE, STAY HEALTHY 🙂 STAY HOME 🙂

UseCase: We have application where we need to use azure app client secret key and certificate for accessing Microsoft Graph APIs. So we decided to use the Azure Key Vault service to store azure app client secret key and certificate for security reasons. But then again to fetch the client secret key and certificate from Key Vault service we need to authenticate and here Managed Identity service come to picture 🙂

Since this article going to be big lets divide this articles into series. This is third article in this series: Creating simple Hello World .Net core application and deploy to Azure as a WebJob

If you didn’t got a chance to go through last two articles, kindly please have a look once –

So lets begin the fun 🙂

Take Away from this article: At the end of this article, we will got to know

  • Creating .Net core console application
  • Publishing .Net core console application to Azure as a WebJob
  • Scheduling the WebJob

Prerequisites:

  • Visual Studio 2019 with Azure development feature installed as shown in below Fig
Visual Studio 2019 with Azure development components (Azure SDKs, tools etc.) installed
Fig : Azure – Visual Studio 2019 with Azure development components (Azure SDKs, tools etc.) installed

Step 1 – Creating .Net Core console application:

  • Create a new project. Here I am using Visual Studio 2019 community edition as shown in below Fig
Azure - Creating a new project - .NET Core console application - Visual Studio 2019
Fig : Azure – Creating a new project – .NET Core console application – Visual Studio 2019
  • Create “Console App (.NET Core)”
Azure - Creating a new project - .NET Core console application - Visual Studio 2019
Fig : Azure – Creating a new project – .NET Core console application – Visual Studio 2019
  • Specify the project and solution name. Here we are giving the name – “KeyVaultDemo
Fig : Azure - Creating a new project - .NET Core console application - Visual Studio 2019
Fig : Azure – Creating a new project – .NET Core console application – Visual Studio 2019
  • Following is the .NET Core console application “KeyVaultDemo” created and make sure it get successfully build
Azure - Creating a new project - .NET Core console application - Visual Studio 2019
Fig : Azure – New project – .NET Core console application created and build successfully
  • Please note here that we dont have “Settings.job” file yet in solution

Step 2 – Deploying .Net Core console application as a Web Job to Azure App Service:

  • Right click on solution and click on “Publish” link as shown in below Fig
Azure - Publishing .NET Core console application
Fig : Azure – Publishing .NET Core console application
  • Once we clicked on “Publish” link, “Publish” dialog will appear as shown in below Fig
  • Select the option “Azure
Azure - Publishing .NET Core console application to Azure
Fig : Azure – Publishing .NET Core console application to Azure
  • In next step select the option “Azure Webjobs
Azure - Publishing .NET Core console application to Azure as Azure Webjobs
Fig : Azure – Publishing .NET Core console application to Azure as Azure Webjobs
  • Next we need to create either new Azure Webjob or need to select existing WebJob.
  • We need to sign in the Visual Studio with appropriate account
Azure - Publishing .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 - asking for Sign In
Fig : Azure – Publishing .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 – asking for Sign In
  • Once we signed in with appropriate account, on “Publish” dialog, we have listed the our App Service which we created as shown in below Fig
Azure - Publishing .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 - listing existing created App Service
Fig : Azure – Publishing .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 – listing existing created App Service
  • Next click on “Finish” button as shown in above Fig, we will have all the summary as shown in below Fig.
Azure - Publishing .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 - Summary of the WebJob
Fig : Azure – Publishing .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 – Summary of the WebJob
  • As soon as we publishing process successfully finished, there is a file called “Settings.job” added to the solution.
  • Same is mentioned in output window as well
  • Please observe the output window, detailed steps are mentioned in it. Which also gives an ideas what happens exactly when we publish our application to the Azure
Azure - Successfully published .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 - details in output window
Fig : Azure – Successfully published .NET Core console application to Azure as Azure Webjobs from Visual Studio 2019 – observe the output window – “Settings.job” file included in solution
  • “Settings.job” file is used for scheduling our Webjob
  • Please have look at following fig – “Settings.job” file contains some sample scheduling entries
  • Here, we are scheduling our Webjob for every minute
  • Please note the syntax for scheduling
Azure -Seetting.job file with various example scheduling entries
Fig : Azure – Seetting.job file with various example scheduling entries
  • After publishing, from App Service page go to Webjobs where we will have our Webjob listed as shown in below Fig
Azure - App Service >> WebJobs listings
Fig : Azure – App Service >> WebJobs listings
  • From WebJobs listings dashboard we will have various options available like “+Add” – for manually adding new WebJob, “Delete” – for manually deleting WebJob, “Refresh
  • If we select particular WebJob we will have “Run” option for running given WebJob
  • We could see the properties by clicking on “Properties” option
Azure - Running the selected WebJob
Fig : Azure – Running the selected WebJob
  • Once we ran the WebJob we get the message on the right top corner “Webjob is now running” as shown in below Fig
Azure - Webjob execution is in progress
Fig : Azure – Webjob execution is in progress
  • We have scheduled the Webjob every minute as per the setting in “Settings.job” file
  • Once Webjob executed successfully, we could see the logs as well by clicking on “Log” link as shown in below Fig
Fig : Azure - Webjobs Logs link from Webjobs listings dashboard
Fig : Azure – Webjobs Logs link from Webjobs listings dashboard
  • Once we clicked on “Logs” link, we will be redirected to WebJob Details page as shown in below Fig
  • On WebJobs Details page we have history or listing of all the executed WebJobs status.
Azure - Webjobs status history
Fig : Azure – Webjobs status history
  • We could click the link under “TIMING” column as shown in above Fig to see the details of WebJob run or output of the job as shown in below Fig
Fig : Azure – Webjob run details

Next ArticleIn next article, we will access the KeyVault keys to access the Microsoft GRAPH API and will discuss managed identity service

We have very good series on Azure, lots of discussion on Azure, please visit – https://knowledge-junction.com/?s=azure

Thanks for reading 🙂 If its worth at least reading once, kindly please like and share. SHARING IS CARING 🙂

Share in Teams:

Enjoy the beautiful life 🙂 Have a FUN 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂

This site uses Akismet to reduce spam. Learn how your comment data is processed.