Поделиться через


TFS and Jenkins Integration

As soon as there is a new code submit to TFS, TFS can notify Jenkins to perform continuous integration build or test. This is effective for unit test as we always would like to trigger unit test to check whether there is any code regression. This blog will cover:

  • How to create the project in TFS.
  • How to submit code change from Visual Studio Code.
  • How to trigger the continuous integration from TFS to Jenkins.

Create Project from TFS

In TFS 2015 Update 3, you are able to click the "New team project" button to create a new project shown below. Let's choose Git as the source control.
12-1

Setup Visual Studio Code

Get the Git repository address of the project just created, clone the project to development machine shown below. Also, it is needed to git config the user name and email.
12-3

Open the local Git repository in Visual Studio Code and can make any code change and submit now. Visual Studio Code will notice the code chang automatically. Click the "commit All" button will commit the change to local git.
12-4
Click the "Push" menu will push the code change to TFS then.
12-5

Configure Jenkins

Create a freestyle project in Jenkins shown below.
12-6

In the Configuration of the newly created project, select Git as the repository of Source Code Management. Both of the Git repository address and a TFS credential are needed shown below.
12-12

Configure TFS

Open the team project administrator page in TFS web portal, there is one tab named "Service Hooks". It supports multiple services not only for continuous integration. Add a new service.
12-7
In the Service page, select Jenkins.
12-8

In the Trigger page, select "Code pushed" which means TFS will notify Jenkins as soon as there is new code change. You can also select "Build completed" if TFS performs a scheduled build by build definition.
12-9
In the Action page, provide the project name which is just created in Jenkins. Both of API token and password are supported and token is recommended.
12-10

Before finishing the configuration, it is suggested to click the "Test" button in the Action page to make sure everything is working fine. If there is 403 error shown below, uncheck "Prevent Cross Site Request Forgery exploits" in Jenkins "Configure Global Security" management portal, and try again.
12-11

Comments

  • Anonymous
    January 12, 2017
    Great post! Easy understanding in such a step by step guide
  • Anonymous
    January 17, 2017
    Thanks for the post! do you have any step by step for TFS as version control rather than git ?
    • Anonymous
      January 19, 2017
      @Fetigue, in Source Code Management, there is "Team Foundation Version Control(TFVC)" option for version control.
  • Anonymous
    March 19, 2019
    @Wu Shai, I do get this errorgitRepository URL http://tfs:8080/tfs/Omaha/Projects/_git/QA.GSS_AUTOMATIONHelp for feature: Repository URLHTTP ERROR 403Problem accessing /job/TFS/descriptorByName/hudson.plugins.git.UserRemoteConfig/checkUrl. Reason: No valid crumb was included in the requestafter giving the tfs url in git...how do i give the password? by default it shows jenkins password or it show nonehow do i give tfs password?can you give more details on thisThanks in advance