Click here to Skip to main content
15,879,239 members
Articles / DevOps / Git

Continuous Integration and Deployment (CI/CD) of ASP.NET Core Application on Azure Web App using Jenkins – Day 3

Rate me:
Please Sign up or sign in to vote.
4.67/5 (7 votes)
28 Nov 2019CPOL4 min read 8.1K   97   6   2
In this article, we’ll focus on Azure Active Directory and Service Principal and integrate Jenkins with Azure Service Principal before we move on to CI/CD of ASP.NET Core application on Azure using Jenkins Azure Pipeline.

  

Theme

This article series will explain using Jenkins for CI and CD of an ASP.NET Core web application on the local development environment, publishing the web application to Azure Web App Service and configuring Jenkins on Azure for continuous integration and continuous deployment of the hosted application. GitHub will DevOps as a source control repository. We’ll create a pipeline using Jenkins that fetches the code from GitHub, builds the code, runs the tests and deploy the package. This will be a repetitive task on each commit to the code located on GitHub.

In the first article of the series, we learned about the concepts, terminology, technologies involved, installing Jenkins, creating ASP.NET Core application and continuous integration of ASP.NET Core application using Jenkins via two approaches, i.e., pipeline approach and freestyle project approach. In the second article, we published the ASP.NET Core application to Azure App Service and Configured Jenkins on Azure.

In this article, we’ll focus on Azure Active Directory and Service Principal and integrate Jenkins with Azure Service Principal before we move on to CI/CD of ASP.NET Core application on Azure using Jenkins Azure Pipeline.

Roadmap

Following is the roadmap we would be following to completely learn end to end development and configurations of Continuous Integration and Deployment (CI/CD) of ASP.NET Core Application on Azure Web App using Jenkins.

Prerequisites

Go through the first two articles of the series before starting this article.

Following are the prerequisites for developers to have on their machines before getting started:

  1. Visual Studio 2017/2019
  2. Dotnet 2.1 SDK installed
  3. Azure Subscription Free/Paid
  4. Java 1.5 or higher
  5. Git account
  6. Git for Windows

Azure Active Directory and Service Principal

The next step is to create an identity for our application as it needs access to our Azure web app. This identity will serve as a service principal that could be assigned certain permissions to operate on the app.

Create an Azure Active Directory and Service Principal

  1. In the Azure portal, click on Azure Active Directory and then on App Registration as shown below:

    Image 1

  2. Click on New Registration to create a new app registration.

    Image 2

  3. Provide a meaningful name. For example, I provided jenkins_sp and select the first option for the supported account types, i.e., Account in this organizational directory only.

    Image 3

  4. Click on Register to create this new Azure AD and service principal.
  5. Navigate to the newly created application, i.e., Jenkins_sp.

    Image 4

Integrate the Application to a Role

To get access to the Azure resources, the application needs to be assigned to a role. For example, if in the Azure subscription, we assign the role to a resource group, then all the resources in that resource group will inherit that role and its permissions.

  1. Navigate to the Subscriptions in the Azure portal. Select the subscription. For example, I have only one subscription, and if I select that, all the resources in that subscription will inherit the role and permissions assigned.

    Image 5

  2. Once selected, the subscription page will open to the right.

    Image 6

  3. Select Access control (IAM).

    Image 7

  4. Select Add role assignment.

    Image 8

  5. In the Add role assignment form, select Role as Contributor, assign access to Azure AD user, group, or service principal. In the Select options, search by typing Jenkins and we see our jeninks_sp, i.e., our service principal. Choose that and save.

    Image 9

  6. Click on the newly created app registration and on the overview page, copy the following values to a Notepad as they would be used while assigning a service principal to Jenkins.
    • Application (client) ID
    • Directory (tenant) ID
  7. Click on Certificates & secrets and add New client secret. Provide it a name and copy the value of the client secret created.

    Image 10

    Now, we need to provide this service principal to the Jenkins running on the URL to have access over Azure resources on the selected subscription.

Integrate Jenkins with Azure Service Principal

  1. On the running Jenkins URL, navigate to Credentials -> System -> Global credentials and click on “Add Credentials”.

    Image 11

  2. Select Kind as Microsoft Azure Service Principal and fill in the following fields:
    • Scope: Global
    • Subscription ID: Your Azure subscription ID
    • Client ID: The copied Application (client) ID from the service principal app
    • Client Secret: The copied value of the secret certificate
    • Tenant ID: The copied Directory (tenant) ID from the service principal app
    • Azure Environment: Azure

Time to integrate Jenkins to the service principal created on the Azure portal.

Image 12

Click on the verify service principal button to verify the details and connection. Once it says, Successfully verified…, click OK.

Image 13

Conclusion

In this article, we focused on Azure Active Directory and Service Principal and integrating Jenkins with Azure Service Principal. In the next and last article of the series, we’ll see how to enable CI/CD of ASP.NET Core application on Azure using Jenkins Azure Pipeline.

History

  • 27th November, 2019: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect https://codeteddy.com/
India India
Akhil Mittal is two times Microsoft MVP (Most Valuable Professional) firstly awarded in 2016 and continued in 2017 in Visual Studio and Technologies category, C# Corner MVP since 2013, Code Project MVP since 2014, a blogger, author and likes to write/read technical articles, blogs, and books. Akhil is a technical architect and loves to work on complex business problems and cutting-edge technologies. He has an experience of around 15 years in developing, designing, and architecting enterprises level applications primarily in Microsoft Technologies. He has diverse experience in working on cutting-edge technologies that include Microsoft Stack, AI, Machine Learning, and Cloud computing. Akhil is an MCP (Microsoft Certified Professional) in Web Applications and Dot Net Framework.
Visit Akhil Mittal’s personal blog CodeTeddy (CodeTeddy ) for some good and informative articles. Following are some tech certifications that Akhil cleared,
• AZ-304: Microsoft Azure Architect Design.
• AZ-303: Microsoft Azure Architect Technologies.
• AZ-900: Microsoft Azure Fundamentals.
• Microsoft MCTS (70-528) Certified Programmer.
• Microsoft MCTS (70-536) Certified Programmer.
• Microsoft MCTS (70-515) Certified Programmer.

LinkedIn: https://www.linkedin.com/in/akhilmittal/
This is a Collaborative Group

780 members

Comments and Discussions

 
GeneralMy vote of 5 Pin
Anil Chauhan 25081-Dec-19 18:33
professionalAnil Chauhan 25081-Dec-19 18:33 
GeneralRe: My vote of 5 Pin
Akhil Mittal2-Dec-19 0:02
professionalAkhil Mittal2-Dec-19 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.