Deploy your .NET applications to Azure with Jenkins


If you are using Jenkins and want to deploy Azure .NET applications, you should read this article.

After reading, you will be able to do Continuous Integration, Continuous Delivery with Jenkins for Azure WebApps basically.

Prerequisites:

   •       .NET web application running on Azure App Services.

   •       Jenkins master or slave Windows machine with Microsoft Build Tools(MSBuild).  Jenkins MSbuild plugin.

   •       Jenkins plugin (Change assembly version plugin)

   •       Jenkins plugin (Version Number Plug-In)

Setup

1. Create a Web Application on Azure on AppServices

You must be sure that your application has already configured for running/working on Azure.

2016-06-22_22-16-30

2. Create deployment slots for your Azure Application

 You should create different environments as you need like testing, staging, development, alpha, beta, production vs…

If your domain’s look like this http://myapp.azurewebsites.net/,

after creating a staging slot, you should have a second environment and access it for your application like this http://myapp-staging.azurewebsites.net/

2016-06-22_22-16-31

 3. Get publish profile for Azure Application

 You must download your needed webapps publish profile from Azure App Services.

2016-06-22_22-16-32

 (Optional) Set your swap options

I recommend that you should create a staging slot and download it’s publish profile to your Jenkins build server.

Because, You should not deploy your applications to production directly, You must test it before.

Finally If the staging deployment and tests have finished, you should configure “Azure Swap” feautures on Azure portal.

2016-06-22_22-16-33

2016-06-22_22-16-34

4. Create and Configure Jenkins FreeStyle Project

4.1. Configure Source Code Management

Configure your source code for getting the latest application code to Jenkins Workspace.

You should define your specific branch name.

2016-06-22_22-16-35

 4.2. Configure Build Triggers

 Configure Poll SCM to “00110” for auto triggering Jenkins job on each check-in operation immediately.

2016-06-22_22-16-36

4.3. Configure Build Environment & Versioning

 If Version Number Plug-In has already installed, there will be an option “Create a formatted version number”.

Check this box and give an environment variable name. We will use it on the build step for build and DLL versioning.

Version Number Format String must be unique for each build. So I recommend to create it with unique parameters like this.

    “${BUILD_YEAR}.${BUILD_MONTH}.${BUILD_DAY}.${BUILDS_TODAY}”

 2016-06-22_22-16-37

4.4. Configure Build

 If Change assembly version plugin has already installed, there will be a build step“Change Assembly Version”.

You should use it for dll file versioning.

$VERSION parameter will be dynamically set on each Jenkins build.

 You should add a step “Execute Windows batch command” for nuget package restoring before the msbuild process.

You should copy nuget.exe file to your custom static location(C:\Scripts\Nuget.exe) on your Jenkins server or you should call it from Jenkins job workspace like this “%WORKSPACE%\.nuget\nuget.exe”

2016-06-22_22-16-38

We have already get Azure publish profile for our webapp. File name must be like this “myazureapp-staging.PublishSettings”

Copy this file to Jenkins custom folder (“C:\Scripts\Azure\MySolution\PublishProfiles”)

Open the publish settings file and copy the userPWD value and paste it to Jenkins Job’s MSbuild command line argument as “/p:Password=xxxxxxxxx

2016-06-22_22-16-39

Add a build step “Build a Visual Studio Project or solution using MSBuild”. Fill in the “MsBuild Build file” for your sln file location. You should use parameters with Jenkins like this. $WORKSPACE\somefolder\myproject.sln

Fill in the command line arguments for publishing the application to Azure App Services.

 /p:DeployOnBuild=true /p:AllowUntrustedCertificate=true /p:PublishProfile=C:\Scripts\Azure\MySolution \PublishProfiles\ myazureapp__staging.pubxml /p:Password=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2016-06-22_22-16-40

5. (Optional) Deploy your specified files with FTP

Use should deploy your files with different sources like DropBox, OneDrive, Github, Bitbucket.. And there is an another deployment option with FTP.

Some of your application files couldn’t included in your solution or you need an another option for deployment.

So you should use FTP deployment as main deployment step or an extra step after the Azure publish process.

 – Create an FTP user on Azure portal and test it with and FTP client program like Filezilla.

 – Create a batch file and run it from Jenkins by adding a build step “Execute Windows batch command”.

 Note: If There is a big total file count, It can be very slow moving files via ftp. Please use an another option.

2016-06-22_22-16-41

2016-06-22_22-16-42

6. Configure Post build notifications

You must be sure that the build has started or finished successfully. So You should add post build actions like mailing and any other communication tools. First of all, they must be configured at Jenkins Configure System page as you need.After that you should run your test automation on Staging environment as your configured pipeline. And could auto swap for Production with Jenkins.

2016-06-22_22-16-43

javafx

Database Operations in JavaFX

By Onur Baskirt / Apr 1, 2016 / 56 Comments
Before started this section, please check the first article and learn How to Start JAVAFX! http://www.swtestacademy.com/getting-started-with-javafx/ At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an...
rest assured

REST API Testing with Rest Assured

By Onur Baskirt / Mar 8, 2016 / 32 Comments
Outline In this post, I will explain what is API and API testing, what is the difference between SOAP and REST services, and how to test REST APIs with Rest Assured Library. What is API? API stands for Application Programming...
extentreports

How to Write Effective CSS Locators

By Onur Baskirt / Oct 1, 2017 / 0 Comments
Hi all, in this tutorial, I will describe you how to write effective CSS locators to interrogate web elements for your automation projects. As a rule of thumb, your interrogation strategy should be in below order: First try to use...
extentreports

Selenium-11: Execute JavaScript with JavascriptExecutor

By Onur Baskirt / Jan 27, 2016 / 15 Comments
Outline Sometimes we cannot handle some conditions or problems with Webdriver, web controls don't react well against selenium commands. In this kind of situations, we use Javascript. It is useful for custom synchronizations, hide or show the web elements, change...
javafx

Getting Started with JavaFX

By Onur Baskirt / Mar 25, 2016 / 0 Comments
When I started to work in my current position, one of my task is to do manual operations for campaign products  every week. After the second week, I thought that I have to automate this task using a GUI based...
extentreports

How to Write Smart XPath Locators

By Onur Baskirt / Sep 24, 2017 / 4 Comments
Hi all, in this tutorial, I will describe you how to write smart and non-brittle XPath locators. When we write our test scripts, we generally prefer to use id, name, class, etc. these kinds of locators. However, sometimes we could not...
extentreports

Selenium-1: Quick Start to Automation with Selenium WebDriver & JAVA & JUnit & Maven & IntelliJ

By Onur Baskirt / Sep 8, 2015 / 26 Comments
Outline Selenium Webdriver is the most popular open source web test automation framework across wide range of browsers and platforms. In this tutorial you will learn how to do web test automation with Selenium Webdriver and the related tools. Audience...
page object model

Page Object Model with C#

By Ege Aksoz / Jun 18, 2017 / 8 Comments
In the previous tutorial, we’ve taken the initial steps and entered the world of automated testing. We also wrote our first automated test. From this point on, since we are not just going to write one test, we need to...
extentreports

How to Select a Date From DatePicker Using Selenium

By Onur Baskirt / Aug 13, 2016 / 6 Comments
When you need to automate a airway, hotel, or similar websites you need to deal with Datepickers and some times it is a little bit cumbersome to select a specific date on the Datepicker or calendar.  In this post, I...
extentreports

Selenium Webdriver Performance testing with Jmeter and Selenium Grid

By Ozgur Kaya / Aug 9, 2016 / 2 Comments
In this post, we will complete Selenium Webdriver Performance testing scenario using Jmeter and Selenium Grid. 1- Install Java 7 or later If necessary https://java.com/tr/download/ 2- Download latest Jmeter version 3.0 or higher. http://jmeter.apache.org/download_jmeter.cgi 3- Download Jmeter PluginsManager JAR file and...
By | 2017-01-13T21:33:42+00:00 June 25th, 2016|Azure, Continuous Integration, Devops, Jenkins|1 Comment

About the Author:

Ozgur Kaya
Özgür KAYA is a Senior Software testing and devops professional with 10+ years of experience. He has worked at Turkcell Global Bilgi, Veripark, Turkcell, N11, Trendyol as system & application administrator, test & devops & test automation engineer, test team lead. Now, he is working as Software Testing Team Lead at EFT Software. He is interested in Continuous Integration & Continuous Delivery configurations, Building Test automation framework in everywhere, Build, Release and Deployment Management, Load & Performance & Stress Testing, Application Administering & Monitoring, Security Testing with OWASP rules, Test & QA team management. You can find detailed information about him on his linked-in page.

One Comment

  1. Avdhesh Paliwal October 28, 2016 at 10:11 pm - Reply

    Hi Ozgu,
    I’m getting this error while trying to deploy WebAPI project to Azure.
    C:\Scripts\Azure\CtbDistributorApi\PublishProfiles\CtbDistributorApi.PublishSettings(1,1): error MSB4068: The element is unrecognized, or not supported in this context.

    Will appreciate your help.

Leave A Comment