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.
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.
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.
Click the "Push" menu will push the code change to TFS then.
Create a freestyle project in Jenkins shown below.
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.
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.
In the Service page, select Jenkins.
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.
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.
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.