Skip to content

Instantly share code, notes, and snippets.

@yancyn
Last active May 24, 2021 03:56
Show Gist options
  • Save yancyn/365a0ea446c4bab8af51 to your computer and use it in GitHub Desktop.
Save yancyn/365a0ea446c4bab8af51 to your computer and use it in GitHub Desktop.
Build .NET Project with Jenkins

Create a Windows Jenkins server to automate build .NET project with MSBuild. Technologies used are MSBuild, nuget, and git. The main reason to setup Jenkins on Windows is explicitly to build Windows application.
**depends on the output you want to build, please choose the right operating system before you start.

TODO

  • Trigger build by git push or tag.
  • Build Unit Test and post result.

Prerequisitions

  • Jenkins
  • MSBuild
  • Git for Windows

Setup Jenkins

  1. Manage Jenkins > Manage Plugins
  • Subversion 2.5.4
  • Git >=2.4 Plugin (and dependencies)
  • MSBuild Plugin
  • Nuget Plugin
  1. Manage Jenkins > Configure System
  • Provide svn version if any
  • Provide git.exe location ie. C:\Program Files\Git\bin\git.exe
  • Provide MSBuild.exe location ie. C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe
  1. Create Jenkins Job

    • Freestyle Project
    • Choose Git > URL > Credential
    • Add Build Steps
      1. Execute Windows Batch command > nuget restore solution.sln (if any)
      2. Build project with MSBuild > solution.sln with parameter /property:Configuration=Release (if any)
    • Add Post-Build Steps.
      1. Archive the artifacts > ProjectFolder/bin/Release/.exe,ProjectFolder/bin/Release/.dll (folder/** means including subdirectories)
  2. Build Now

Enable Gitlab Push To Build

  1. Manage Jenkins > Manage Plugins > Add GitLab Plugin & Gitlab Hook Plugin.
  2. Manage Jenkins > Configure System > Test Connection (after fill up).
  3. Create a new build job as appropriate.
  4. Manage Project > Configure > Build Triggers > Build when change is pushed to Gitlab.
  5. Go to gitlab project setting > web hooks > Add web hook http://localhost:8080/project/ProjectName%20Build > Test Hook to see result.
  6. Done.

Integrate with xUnit

Ensure xunit.runner.console in nuget package.

  1. Install xUnit plugin.
  2. Add Windows batch command after build > packages\xunit.runner.console.2.1.0\tools\xunit.console.exe MyProject.Test\bin\Release\MyProject.Test.dll -xml MyProjecct.Test\bin\Release\MyProject.test-result.xml
  3. Add post build actions > Publish xUnit test result report > **/Release/*test-result.xml
  4. Enjoy.

Setup Free Online Jenkins Server

Add Jenkins cattrige at OpenShift Web Console.

Setup OpenShift Client Tool

  1. Install RubyGem 1.9.3 on Windows
  2. C:> gem install rhc
  3. C:> rhc setup
  4. C:> openshift.redhat.com
  5. C:> login@email.com
  6. C:> password
  7. C:> rhc create-app jenkins jenkins-1 --no-git
  8. Done

see https://developers.openshift.com/en/getting-started-windows.html
**ignore the error message 'It appears that your reverse proxy set up is broken.'

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment