Към съдържанието
  • Услуги
    Нашият подход
    Предлагаме персонализирани технологични услуги в глобален мащаб, с чиято помощ компаниите успяват да осъществят своята дигитална трансформация.
    Научи повече
    • Нашият подход
    • Artificial Intelligence
    • Development
    • Design
    • Digital Experience Platform
    • Data & Analytics
    • Cloud & DevOps
    • Security & Compliance
    • Support
  • Индустрии
    Нашите проекти
    Благодарение на нашата експертиза в изграждането на стратегия, дизайн и софтуер клиентите ни постигнат целите на своята дигитална трансформация.
    Научи повече
    • Нашите проекти
    • Здравеопазване
    • Земеделие
    • Промишленост
    • Финансови услуги
    • Образование
  • За нас
    За нас
    В продължение на повече от 20 години си партнираме с компании от разнообразни сектори и с различни мащаби и решаваме най-сложните им бизнес проблеми.
    Научи повече
    • За нас
    • Локации
    • Събития
    • Новини
  • Кариери
    Стани част от екипа
    Дай тласък на кариерата си. Предлагаме вълнуващи възможности на всеки етап от жизнения цикъл на софтуерната разработка.
    Научи повече
    • Стани част от екипа
    • Отворени позиции
    • Интервю процес
    • Придобивки
    • Обучения и развитие
  • Публикации
    Повече от нас
    Прочети най-новите ни блог постове, виж последните ни видеа и разгледай библиотеката ни с е-книги, в които нашите експерти споделят безценни насоки.
    Научи повече
    • Повече от нас
    • Блог
    • Видео
    • Е-книга
  • Контакти
Menu
април 09, 2015

Jenkins CI in MVC.NET Part 1: Install, Setup and Build

More on companies’ integration of continuous integration servers in their work process and their benefits.

Continuous integration is widely used term today. The main reason for this is because more and more companies are integrating continuous integration servers in their work process. The benefits of this can be many. From faster issue detection, quick builds and deploys, project risk management, open tasks track, etc. All benefits and good practices can be found in books like „Continuous Integration“ by Paul Duvall, Steve Matyas, and Andrew Glover or „Continuous Delivery“ by Jez Humble and David Farley. For that reason there is a lot of tools created to resolve this tasks. Tools like „Team Foundation Server“ and „Bamboo“ have good integrated solutions, but they are paid and not all companies are willing to use them. Another alternative is Jenkin CI which is pretty popular mainly because it is very flexible and can perform wide array of tasks. But this flexibility come with the price, that it is not very easy to setup. So in series of blog post I will try to present to you a fairy common and complete setup of Jenkins continue integration process for a single MVC.NET application. The first step is installing the server itself under windows, adding some required plugins and tools in order to build .NET application and creating a new Job that build our application.

Installing

  1. Go to jenkins-ci.org download and install Jenkins for Windows. After the setup finish it will automatically start it.
    Note that IIS is not required. Jenkins will run its own server.
  2. Visit the https://microsoft.com/en-US/download and install the latest version of Windows Software Development Kit. Last location is here.
  3. Go to your Jenkins manage page and make sure the Subversion plugin and/or the Git plugin are installed, so you can download your projects.
    • In order to install git plugin you need to download git itself first. Go to http://git-scm.com/download and download the latest version.
    • After you install git plugin you will need to set the Git location in the configuration. Example under git installations you may enter Name: „Default“ and Path: „c:/Program Files (x86)/Git/bin/git.exe“ if this is where you installed git.
    • Git plugin install ‘ssh credentials’ plugin. It is a good idea to crate a ssh user what jenkins is going to use when connecting git. When using the plugin place your .ssh folder on the main drive root (Example c:.ssh).
  4. Go to the Microsoft download page and download the latest „Microsoft build tools“ and install it. The ‘Microsoft build tools’ include MSBuild. After the install in the „Program Files (x86)“ folder you should have MSBuild folder.
  5. Go to System -> Advanced system settings -> Environment Variables and set the PATH to point to the MSBuild folder (ex: C:Program Files (x86)MSBuild14.0Bin). After Path is set you need to restart jenkins. You can do this by navigating to „YourJenkinsDomain/restart“ page.
  6. Download the NuGet executable. This tool is used to restore NuGet packages used by the project. NuGet is available at http://nuget.org/nuget.exe.
    It is good idea to hold all tools in one folder so with our example we will use c:Tools to hold all required tools. So the NuGet executable cab be in the ‘c:ToolsNuGetNuGet.exe’

Setup Git

I think the best way to use continuous integration with git is to set all developers users to pull from the master branch, but not to be able to push to it. The only user that will be able to push to the master will be Jenkins. In this way on the master branch will always be a stable version and the developers will not use broken builds. This flow will look like this:
  1. [You] Pull from master.
  2. [You] Create new branch and make changes.
  3. [You] Rebase with master and push to origin premaster (Push to master will not be allowed).
  4. [CI] Get the latest version from premaster branch.
  5. [CI] Build, run test and analyzes tools.
  6. [CI] Merge with master.

With this scenario on the master branch resign only stable build version. If  QA or client require a new build version to be deployed to the test server this can be initialized with a stable build, although component or functional test can be run at this point.

Unfortunately, revoking write permissions to master is not possible in Github (It is possible in GitLab by making the master branch protected). We may use other git servers to manage this scenario.

Some example config in ‘gitolite’ can be:

@all-devs = alice bob carol
@ci       = jenkins
@admin    = supermen

repo test
    RW+                = @admin
    RW    master$      = @ci
    RW    premaster$   = @all-devs
    RW    refs/heads$  = @all-devs
    R     master$      = @all-devs

With this configuration the users Alice, Bob and Carol can modify the branches and the premaster origin, but can only read from the master. The Jenkins user however can modify the master.

Using Git on Developer Machine

Let we assume I am „Alice“ and I want to start using git and Jenkins in my project. When I clone a repository I can start pulling from the master branch and create branches out of it, but I can not push to the master branch. I need to push to a premaster branch (The branch that Jenkins track) after a change is made.

Setup Git at Jenkins

In order to make sure Jenkins is up and running we can make it build a project and push it to master.

  1. Go to Jenkins page and Go to ‘New Item’.
  2. Enter a name and select a project type (Freestyle project is ok for the test).
  3. On the ‘Source Code Management’ section choose Git (if you use another VCS setup it here). Set the repository path and credentials.
    • If you use gitolite you can reference this.
    • If you use gitlab you can install the gitlab plugin and use that.
  4. Check ‘Poll SCM’. This option will allow Jenkins periodically to check for new commit in version control system. For example ‘H/10 * * * *’ will check for new version every 10 min.
  5. At ‘Add post-build action’ select ‘Git Publisher’.
    Check Push Only If Build Succeeds.
    Add Banch origin master to push to.

You can at this point try to push something to the repository and check if it is merged to master branch.

Setup SVN

Setup for SVN is straightforward it do not allow update from one branch and commit to another so the only thing you do is update.

Build a project with Jenkins

  1. Create a project
    • File => New => Project => ASP.NET Web Application.
    • Set some name, for example: „FirstBuild“.
    • Select the version control folder.
    • From the templates select MVC.
  2. First thing to do is to clean the project if there is some files left from old build. If you use the (Default) option MSBuild may find the solution file by itself. Otherwise you have to specify Build File.

    MSBuild Build File:                     ${WORKSPACE}FirstBuild.sln
    MSBuild Command Arguments: /t:Clean /v:m /nologo

    As extra clean you can use bash script that delete all bin and obj folders in the projects.

    Jenkins CI MSBuild Clean
    Jenkins CI MSBuild Clean
  3. After the clean we need to restore all NuGet packages. You do this with a bash script and accessing NuGet.exe.
    If your solution is named FirstBuild and you have installed NuGet at the specified folder you can execute the fallowing Bash script to restore your libraries.

    REM "Restore libraries."
    "C:ToolsNuGetNuGet.exe" restore FirstBuild.sln
  4. Building the project with MSBuild. We can use the options:
    • /t:Build – start a build.
    • /p:Configuration=Debug – build in Debug mode. Use can build in Release mode, also.
    • /v:q – sets the verbosity to quit so the log not to be poluted with too much information.
    • /nologo – remove the some unneeded information from the log file.

    MSBuild Command Arguments: /t:Build /p:Configuration=Debug /v:q /nologo

    Jenkins CI MSBuild Debug
    Jenkins CI MSBuild Debug
  5. Before you build it you must remove from all web project (.csproj) files the Visual Studio targets paths. Open project files with text editor and remove the „PropertyGroup“ above Imports. It should look like this:
    <PropertyGroup>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
        <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>

Post-build Actions

As extra post-build actions you can use the fallowing plugins

  • Task Scanner Plugin
    Plugin that scan for open task. In order to scan for tasks you need to specify a file scan pattern. This is one example that scan all .cs files and the javascript files in the „Scripts“ folder, except the modernizer and jquery.

    Files to scan:      **/*.cs, FirstBuildScripts*.js
    Files to exclude: FirstBuildScriptsmodernizr-2.6.2.js, FirstBuildScriptsjquery-2.1.1.js

  • Worksplace Cleaner Plugin
    The plugin can clean up the workplace after build finish.
    If you use this plugin and remove the /obj and /bin folders, MSBuild cleanup is not required.

References

  • http://www.yegor256.com/2014/07/21/read-only-master-branch.html
  • http://devsops.blogspot.com/2013/01/gitlab-jenkins-and-puppet-playing.html
Тагове
  • Software Development
  • Security
Сподели
  • Share on Facebook
  • Share on LinkedIn
Сподели
  • Share on Facebook
  • Share on LinkedIn
Запишете се за нашия бюлетин
Запишете се за нашия бюлетин

Препоръчани публикации

Blog

Secure Your Future with Post-quantum Cryptography

Blog

Protecting Client Data with AWS: Ensuring Trust in the Digital Age

  • LinkedIn
  • Instagram
  • Facebook
United States
MentorMate1350 Lagoon Ave, Suite 800
Minneapolis
, MN 55408

+1 612 823 4000
Bulgaria
67 Prof. Tsvetan Lazarov Blvd.
Sofia 1592, Bulgaria,
+359 2 862 2632
Sweden
Gustav III:s Boulevard 130
P.O.Box 3069
SE-16903 Solna

+46 10 481 00 00
Paraguay
Carlos M. Gimenez 4855
Asunción, Paraguay

+595 21 327 9463

Copyright © 2025 MentorMate, LLC

  • Политика за бисквитки
  • Политика за защита на личните данни
This site is registered on wpml.org as a development site. Switch to a production site key to remove this banner.