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. Атанас Атанасов Software Development Manager - .NET Даниела Назим HR Manager Димитър Добрев CTO Eлеонора Георгиева VP of Delivery, MentorMate Георги Дормишев System Administration Manager Георги Петков Delivery Manager, MentorMate Ивайло Костадинов Director of Software Development - .NET, MentorMate Жени Кючукова Director of Quality and Process, MentorMate Nick Curran Director of US Development Стефан Цвятков Director of Software Development - Mobile, MentorMate Стефан Цанев VP of Operations, MentorMate Веселин Добрев Facility and Purchasing Manager, MentorMate Annika Hey Atanas Atanasov Björn Stansvik Founder & Chief Executive Officer, MentorMate Daniela Nazim Dimitar Dobrev Craig Knighton Chief Operating Officer, MentorMate Eлеонора Георгиева Global VP, Delivery, MentorMate George Dormishev System Administration Manager Georgi Petkov Delivery Manager Ивайло Костадинов Director, Software Engineering - .NET, MentorMate Jamie Bolseth President, MentorMate Jay Miller President, MentorMate Жени Кючукова Director, Quality Engineering, MentorMate Jessica Anderson VP of Finance and Administration, MentorMate Liz Spolyar Global Director, Continuation Engineering, MentorMate Nick Curran Николай Любчев Global Director, Talent Acquisition, MentorMate Стефан Цвятков Director, Software Engineering - Mobile, MentorMate Стефан Цанев Chief Financial Officer, MentorMate Vesselin Dobrev Силвия Василева Solutions Architect, MentorMate Sylvia Vassileva Software Development Manager Красимир Николов VP of Technology, MentorMate Филип Гайтановски Filip Gajtanovski Красимир Николов VP of Technology, MentorMate Katherine Kelly Director of Operations (USA), MentorMate Ryan Peña Social Media & Events Manager Carrie Siewert Brady Swanson Global Director, Marketing, MentorMate Eve Poeschl MentorMate Alumni Ryan Peña Васил Василев Vassil Vassilev Павел Петров Director, Software Engineering - LAMP&FE, MentorMate Иван Пеев Senior Technology Manager Ivan Peev Bob Reuss MentorMate Alumni Грета Ямачева QA Manager Вера Петкова QA Manager, MentorMate Greta Yamacheva Robert Samuelsson General Manager, MentorMate Robert Samuelsson General Manager (Sweden) Kyle Simmons Solutions Architect Robin Thomas Solutions Architect Наталия Найденова Solutions Architect, MentorMate Kyle Simmons Robin Thomas Nataliya Naydenova Adam Malone Alex Krasny Александър Димитров Enterprise Architect, MentorMate Andrea Kates CEO, LaunchPad Central Андрей Маринов Software Development Lead - iOS, MentorMate Anurag Shukla Aron Wolde Ashley Goodridge Benjamin Gramlich Chris Black Colin Lee Добринка Табакова Software Development Lead - iOS, MentorMate Doug Leatherman Emily Genco Gavin Finden Graham Klang Хюсеин Хюсеинов QA Architect, MentorMate James Williams John Byrne Лазар Петракиев Любомир Добрев Senior .NET Developer, MentorMate Lyubomir Velkov Mark Smith Roger Ferguson Ryan Fortune Ryan Blake Sarah Rockholt Stefanie Trimble Stephen Fluin Tom Clemens Director of Marketing, MentorMate Adam Malone Alexander Dimitrov Enterprise Architect Andrea Kates , LaunchPad Central Andrew Eklund Andrew Marinov Angel Nikolov Anurag Shukla Aron Wolde MentorMate Alumni Ashley Goodridge Benjamin Gramlich Chris Black Christa Haeg MentorMate Alumni Colin Lee Ian Good Global VP, Operations, MentorMate Deyan Stoynov Dimitar Danailov Dobrinka Tabakova Doug Leatherman Emily Genco MentorMate Alumni Fanka Vassileva Gabriela Zagarova Gary Conkright CEO, physIQ Gary Fingerhut Gavin Finden Georgi Graham Klang Hyusein Hyuseinov Senior Automation QA Iva Jack Cosentino James Williams Krasimir Gatev Senior Android Developer Lazar Petrakiev Lyubomir Dobrev Lubomir Velkov Marin Yotovski Mark Smith MentorMate Alumni Martin Dimitrov Martin Kalyonski Mike Hagan Nikolay Andonov Nikolay Arhangelov Riley Panko Roger Ferguson John Byrne Kaloyan Stoilkov Kosta Hristov Ryan Sysko Ryan Blake Sarah Rockholt MentorMate Alumni Sean McDevitt , Sensei Siyana Slavova Stanislas Walden Stanislav Atanasov Stanislava Bogdanova MentorMate Alumni Stefanie Trimble Stephen Fluin Stoyan Stoyanov Tessa Cacek Tom Clemens MentorMate Alumnus V8 JavaScript Engine Viktor Mitev Yolanda Petkova Pete Anderson , Target Нели Тодорова Software Development Manager - LAMP, MentorMate Росен Колев Technology Principal, MentorMate Атанас Дюлгеров Project Manager Мартин Димитров Senior .NET Developer Станимир Николов Software Development Lead - iOS, MentorMate Георги Бъчваров Solution Architect, MentorMate Злати Пехливанов Software Architect, MentorMate Ася Манолова Software Developer - LAMP, MentorMate Димитър Михайлов Design Lead, MentorMate Светозар Михайлов UI Designer, MentorMate Диляна Тоцева QA Manager, MentorMate Никола Асланов Senior QA Analyst Васил Нончев Software Development Manager, MentorMate Rosen Kolev Technology Principal Dimitar Mihaylov Nikola Genov MentorMate Alumni Neli Todorova Даря Добрева Senior L&D Advisor, MentorMate Yavor Dimitrov Jake Koelln Sr. Account Manager, MentorMate Shelby Schouweiler Contract Administrator, MentorMate Панайот Тодоров Senior .NET Developer Бистра Маркова Senior Talent Acquisition Specialist Георги Каранедялков Software Development Lead - Android, MentorMate Станислав Станчев Delivery Lead, MentorMate Тунг Лам Нгуен Senior Java Developer Ангел Николов Александър Михайлов Software Development Lead - Front-end Денислав Ганчев Technology Principal, MentorMate Стефан Шопов QA Manager, MentorMate Мирослав Андонов Галина Тритакова Talent Acquisition Lead, MentorMate Димитър Гаджев Константин Русев Senior Software Developer, MentorMate Даниел Парашкевов Software Development Lead - .NET, MentorMate Милен Ламбев Software Development Manager, MentorMate Радослав Глушков Software Development Lead, MentorMate Стефан Стайнов Software Development Manager - .NET, MentorMate Явор Димитров Гюрай Мюмюн Senior Android Developer, MentorMate Борислав Димитров Senior Android Developer, MentorMate Цветан Смърдански Senior .NET Developer Марин Маринов QA Manager, MentorMate Tsvetelina Lazarova MentorMate Alumni Николай Архангелов Software Architect Венета Димитрова Android Developer Dimitar Gadzhev Николай Димитров Software Development Lead - .NET, MentorMate Stanislas Walden Николай Андонов Пламен Стоев Software Development Manager - Front-end, MentorMate Александра Маринова Software Development Lead - .NET, MentorMate Мартин Маляков Software Development Lead - .NET, MentorMate Цветелина Лазарова Experience Designer Димитър Николов Software Development Lead - Java, MentorMate Мила Петрова-Димитрова QA Manager, MentorMate Надежда Йорданова QA Analyst, MentorMate Дениз Хашимов Software Development Lead, MentorMate Венелин Венелинов Software Development Lead - LAMP, MentorMate Jake Nelsen Георги Филипов Software Development Lead - .NET, MentorMate Zlati Pehlivanov Senior Software Engineer II Kate Tolmie Христо Савов Software Development Manager - Java Тихомир Минчев Senior Automation QA, MentorMate Мартин Ангелов Director, Software Engineering - LAMP&FE, MentorMate Dimitar Zhelev Димитър Желев Software Development Lead - .NET, MentorMate Joel Swenson Content Manager Кирил Иванов QA Lead, MentorMate Виктор Христосков Software Development Lead - iOS, MentorMate Violeta Nikolcheva Database Developer Виолета Николчева Database Developer, MentorMate Биляна Къдъкевлиева Senior Automation QA, MentorMate Chris McLeod Antonii Georgiev Антоний Георгиев Alexander Rusev Александър Русев Front-end Developer Matt Erickson Public Relations & Social Media Manager, MentorMate Matt Erickson Brian Buchkosky Global Director, PMO, MentorMate Силвия Петрова Manager Business Analysis, MentorMate David Tran MentorMate Alumni Kristin Krueger Junior Experience Designer, MentorMate Kristin Krueger Даниел Ранков MentorMate Alumni, MentorMate Любомир Бамбов Cloud Engineer Александър Александров Lead Business Analyst, MentorMate Иван Великов System Administration Lead, MentorMate Павел Павлов Cloud & DevOps Lead, MentorMate Звезделин Николов System Administrator, MentorMate Магдалена Червенкова Lead Business Analyst, MentorMate Ясена Пейчева Business Analyst, MentorMate Magdalena Chervenkova Николай Николов QA Lead, MentorMate Denny Royal Chief Design Officer, MentorMate Joe Bodell MentorMate Alumni Joe Bodell Technical Account Strategist, MentorMate Виктория Чучумишева HR Manager, MentorMate Мартин Кочев MentorMate Alumni, MentorMate Юлия Поптодорова Project Coordinator Donada Bichaku Business Analyst Евгени Манов Senior UX/UI Designer, MentorMate Тодор Тодоров Senior Cloud Engineer, MentorMate Христо Стоянов Cloud & DevOps Lead, MentorMate Калина Текелиева Senior Content Marketing Artist, MentorMate Kalina Tekelieva Senior Content Marketing Artist Йосиф Генчев UI Designer, MentorMate Невена Цонева Lead Business Analyst, MentorMate Христо Бахчеванов Senior Business Analyst, MentorMate Daniel Rankov MentorMate Alumni Alexander Alexandrov BA Lead Joel Swenson Editor, MentorMate Живко Дуцов Software Architect, MentorMate Димитър Търкаланов MentorMate Alumni Атанас Лазаров MentorMate Alumni, MentorMate MentorMate Никола Донев SysOps & DevOps Lead, MentorMate Димитър Раев Software Development Lead - LAMP, MentorMate Калина Минева QA Lead, MentorMate Clint Rowles VP, Business Development, MentorMate Nikola Donev SysOps & DevOps Lead Цеко Цолов Senior Software Developer Denislav Lefterov MentorMate Alumnus Dilyana Kodjamanova MentorMate Alumni Денислав Лефтеров MentorMate Alumni Диляна Коджаманова MentorMate Alumni Chris McLeod Senior Solutions Consultant Emma Jorstad Project Manager, Lead Emma Jorstad Project Manager Lead Георги Иванов Technology Principal Quality Engineering, MentorMate Мартин Панайотов Senior iOS Developer, MentorMate Веселина Василева Lead Business Analyst, MentorMate Георги Георгиев Software Development Manager - LAMP, MentorMate Никола Генов MentorMate Alumni, MentorMate Жарко Петровски MentorMate Alumni, MentorMate Jordan Keating Design Director, MentorMate John Blake Senior Account Manager Tyler Compton Nikola Peevski Software Developer — Lamp & Front-End Елвис Бабуров BA Lead, MentorMate Aaron Whitney Director of Client Strategy, MentorMate Екатерина Стаматова QA Lead, MentorMate Велислава Минкова QA Lead, MentorMate Илия Янев QA Architect, MentorMate Йоана Лалова Senior QA Analyst, MentorMate Юмюгюл Кязимова Senior QA Analyst, MentorMate Ива Накова QA Analyst, MentorMate Veliko Ivanov Cloud Architect Никола Пеевски Enterprise Architect, MentorMate Велико Иванов Cloud Architect, MentorMate Suzanne O’Brien Staffing Manager Димитър Великов Software Development Lead - LAMP, MentorMate Светлин Станчев Software Development Lead - Front-end, MentorMate Явор Вълчев Software Development Manager - .NET, MentorMate Todor Todorov MentorMate Alumni Kate Stamatova QA Lead Петко Стоянов Software Development Manager - .NET Веселин Хитров Software Development Lead - LAMP, MentorMate Станислав Михайлов Software Development Manager, MentorMate Петя Иванова Director, Software Engineering - Java, MentorMate Frank Anselmo Global Director, Project Management Мартина Даскалова QA Analyst, MentorMate Gyuner Zeki Solutions Architect Боян Икономов Senior Cloud Engineer, MentorMate Румяна Кушева Manager, Project Management, MentorMate Петър Йовев Senior Project Manager, MentorMate Росен Николов Business Analyst, MentorMate Гюнер Зеки Solutions Architect, MentorMate Галин Станчев QA Analyst, MentorMate Цветан Триов Software Development Lead - .NET, MentorMate Sarah Hoops Brenden Diehl Атанас Иванов Software Development Lead - LAMP, MentorMate Владимир Миндов Software Development Lead - .NET, MentorMate Анна Кривова Software Development Lead - Front-end, MentorMate Ивелина Кавалова Senior Business Analyst, MentorMate Ivelina Kavalova Senior Business Analyst, MentorMate Paul Sanders MentorMate Alumni Росен Ранков Data & Analytics Manager, MentorMate Боян Стоянов Senior Data Engineer, MentorMate Людмил Кирилов Senior Data Engineer, MentorMate Георги Мирков Senior Data Engineer, MentorMate Jim Cikanek Senior Client Strategist Самуил Яновски Software Development Manager - Android, MentorMate Йоана Петрова UX Designer, MentorMate Ирена Янкова UX Designer, MentorMate Красимир Гатев Senior Android Developer, MentorMate Кристина Горялова Talent Acquisition Manager, MentorMate Elena Petrova HR Specialist Jay Matre Senior Business Architect, MentorMate Lilyana Dimitrova MentorMate Alumni Josh Marquart Chief Strategy Officer, MentorMate Mario Gorki Senior Mobile Developer Кристина Горялова Talent Acquisition Manager Марио Горки Senior Mobile Developer, MentorMate Елена Петрова HR Specialist, MentorMate Симеон Жеков Junior Cloud Engineer, MentorMate Simeon Zhekov Cloud Engineer Hristo Stoyanov MentorMate Alumni Ben Wallace Enterprise Architect Sebastian Ortiz-Chamorro VP of Engineering, Latin America Consuelo Merino Director of Operations, Latin America 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 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. Visit the https://microsoft.com/en-US/download and install the latest version of Windows Software Development Kit. Last location is here. 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). 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. 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. 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: [You] Pull from master. [You] Create new branch and make changes. [You] Rebase with master and push to origin premaster (Push to master will not be allowed). [CI] Get the latest version from premaster branch. [CI] Build, run test and analyzes tools. [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. Go to Jenkins page and Go to ‘New Item’. Enter a name and select a project type (Freestyle project is ok for the test). 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. 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. 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 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. 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 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 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 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 DevelopmentSecurity Сподели Share on Facebook Share on LinkedIn Share on Twitter Сподели Share on Facebook Share on LinkedIn Share on Twitter Запишете се за нашия бюлетин Запишете се за нашия бюлетин