Tuesday, October 27, 2015

Setup Jenkins Server with Proxy Setting and Gitlab Integration Part 1

Jenkins Setup

Here are the steps which we need to configure Jenkins on a build server.
   1. Download Jenkins from https://jenkins-ci.org/
                - Currently installed version is 1.632
   2. Configure Global Security
a. Enable Security
b. Set to use Jenkins Own Database, and check the Allow user to sign up. [Required for first user sign up if not created already.]
c. Set Authorisation to Logged in user can do anything

Jenkins Proxy

e.      Signup and un-check “Allow users to signup”.
   3. If Jenkins is behind a proxy than you would need to configure it to have access to the internet. This is the part took me some time to figure it out. J

Go to Jenkins -> Managed Profiles -> Advanced tab and set proxy settings
Proxy


Click on the Check now button at right bottom to test.

Check Proxy




   4.Install plugins
a.Git Plugin
b.GIT Client Plugin
c.GitHun plugin
   5. Install Git , current installed version is 2.6.1
a. Update the git installations forlder under setting Jenkins->Manage Jenkins-> Configure System
Git Path

               

   6. Go to Jenkins Credentials
a.Add Domain “domain name”
b.Add your gitlab credentials in it.
Setup git repository in the Project configuration.

   7. Created public key for Jenkins
   8. Update Proxy Settings for the build Server
a.Add http_proxy and https_proxy environment variables

b.Add http proxy in machine.config
<system.net>
    <defaultProxy>
      <proxy proxyaddress="http://<Proxy name>:<port>" bypassonlocal="false"/>
    </defaultProxy>
  </system.net>
   9.Install Tools on Jenkins server
a.Install MSBuild Tools full
b.Install SSDT Toools using the online installer
c.Install Windows SDK
d.Install ASPNETMVC4
   10.Copy Microsoft folder to Jenkins server to the directory C:\Program Files (x86)\MSBuild. This is required for build targets.
   11.Use Powershell script to build the solution. It is added to solution under build folder.
Script first update the AssemblyFileVersion and AssemblyVersion. Updates the BuildNumber with Jenkins Build Number.

#set the line pattern for matching
    $linePattern = 'AssemblyFileVersion'

    #get all assemlby info files
    $assemblyInfos = gci -path $env:ENLISTROOT -include AssemblyInfo.cs -Recurse

    #foreach one, read it, find the line, replace the value and write out to temp
    $assemblyInfos | foreach-object -process {
        $file = $_
        write-host -ForegroundColor Green "- Updating build number in $file"
        if(test-path "$file.tmp" -PathType Leaf)
        {
            remove-item "$file.tmp"
        }
        get-content $file | foreach-object -process {
            $line = $_
            if($line -match $linePattern)
            {
                #replace the last digit in the file version to match this build number.
                $line = $line -replace '\d"', "$env:BUILD_NUMBER`""
            }

            $line | add-content "$file.tmp"

        }
        #replace the old file with the new one
        remove-item $file
        rename-item "$file.tmp" $file -Force -Confirm:$false
}

# Start the build process
$msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MsBuild.exe"
$solutionPath = $ENV:WORKSPACE + "\<SolutionName>.sln"
$collectionOfArgs = @($solutionPath, "/p:VisualStudioVersion=12.0", "/t:rebuild", "/p:Configuration=Release")

& $msbuild $collectionOfArgs
  12.Once build is successful verify the version is updated or not by checking the properties of the Assembly.

  13.Running unit test cases with Jenkins
BuildScript.ps1 PowerShell Script is added to Solution build folder. Add a new Build Step to Run the PowerShell script and add the script.

Note: To make sure nunit tests are run we need to have .net Framework 3.5 installed on the Server. If you are able to install the framework from the Server Roles and Features.


 Happy coding!!

No comments:

Post a Comment