Visual Studio Team Services plugin

The Visual Studio Team Services plugin from CloudBees is deprecated and customers are recommended to use the Jenkins Team Foundation Server plugin moving forward.

The Visual Studio Team Services plugin let you configure Jenkins to integrate with your Visual Studio Team Services account and setup CI jobs for your VSTS Git repositories. plugin do support branch and pull-request detection, as well as post-commit build triggers.

Development teams using Visual Studio Team Services can trigger Jenkins jobs based on source Git repository using a post-commit web hook. With a minimal setup on VSTS, they can setup a complete Continuous Delivery pipeline using such web hooks.

They also can rely on Jenkins to connect on your VSTS account and automatically detect branches and pull-requests (using multi-branch job types). With such a setup, team can rely on branches or pull-requests based development pipeline, and have Jenkins automatically setup to monitor the branches being used and publish build status.

Installing the Visual Studio Team Services plugin

  • Navigate to 'Manage Jenkins / plugin Manager' and ensure that the Visual Studio Team Services plugin is installed.

plugin manager visual studio team services
Figure 1. Jenkins - plugin Manager - Visual Studio Team Services plugin

Setting up Visual Studio Team Services Web Hook

The Visual Studio Team Services plugin do expose a generic web-hook receiver for Visual Studio Team Services to notify Jenkins on repository events. On VSTS repository administration view, 'Service Hooks' tab you can register hooks to integrate with external services. Visual Studio Team Services plugin do support generic "Web Hook" with following events:

  • Code pushed

  • Pull request created

  • Pull request updated

Service Hook can be created for all repositories in your account or for a specific repository and/or branch. Configuring a global hook for all repositories and branches make it simpler for you to configure your Visual Studio Team Services / Jenkins integration, as you won’t need additional setup on Visual Studio Team Services to configure new projects.

  • Go to your Visual Studio Team Services account dashboard.

  • Select 'Manage Account' (gear icon top right).

  • Select Default Collection to be configured.

  • Click 'View the project administration page'

  • Select 'Service Hooks' tab Please note Visual Studio Team Services do also offer a "Jenkins" Service Hook which can be used to trigger a specific Jenkins job with adequate authorization token. This Service Hook isn’t related to Visual Studio Team Services plugin.

service hook
Figure 2. Service Hook Setup
  • Click the Add (plus) button.

  • Select 'Web Hooks'

  • Select event trigger

  • Enter CloudBees Jenkins Enterprise URL and append /vsts-webhook/. You don’t need authentication for this specific web hook URL.

  • You can use the 'Test' button to check everything is well setup, then save.

service hook2
Figure 3. Service Hook Setup

In your Jenkins job(s), you can now configure Build trigger "Build when a change is pushed to Visual Studio Team Services". With this option enabled, Jenkins will listen to Visual Studio Team Services events, and will compare enabled jobs SCM configuration to the notification source Git repository URL. If current job do match a Git commit notification, a polling cycle will run to check repository for changes and trigger a build if necessary.

build trigger
Figure 4. Build Trigger Setup

Creating a Multi Branch job

The Visual Studio Team Services plugin is compatible with the Jenkins Branch API. Visual Studio Team Services git repositories appear as SCM sources in job types compatible with the Jenkins Branch API such as the Multibranch Pipeline plugin.

Using "Jenkinsfile" to define the build configuration with the source code

Multiple branches of a source code repository may require different build configurations. To solve this problem, the Multibranch Pipeline plugin uses a job definition stored with the source code in a file named Jenkinfile located at the root of the repository.

The Jenkinsfile uses the standard Jenkins Pipeline syntax. You just have to replace the source code checkout step (e.g. git 'https://github.com/my-org/my-repo.git') with a special step checkout scm.

Sample 'Jenkinsfile' for a Maven project
node {
  stage 'Build and Test'
  env.PATH = "${tool 'Maven 3'}/bin:${env.PATH}"
  checkout scm
  sh 'mvn clean package'
}

The Jenkins Multibranch Pipeline plugin will index the git repository and create one build job per branch and per pull request containing a file Jenkinsfile.

Jobs created for pull requests are automatically deleted when the pull requests are closed.

Installing the Multibranch Pipeline plugin

plugin manager workflow multi branch
Figure 5. Jenkins - plugin Manager - Multibranch Pipeline plugin

Creating a Jenkins Multibranch Pipeline job to build all the branches and pull requests

  • Create a Jenkins Pipeline Multi Branch project

new multibranch workflow
Figure 6. Jenkins - New Pipeline Multi Branch Project
  • Navigate to the 'Branch Sources' section,

  • Select 'Visual Studio Team Services' in the 'Add Sources' dropdown list,

scm source
Figure 7. Jenkins - Multibranch Pipeline Project - Branch Sources
scm source 2
Figure 8. Jenkins - Multibranch Pipeline Project - Branch Sources - Visual Studio Team Services
  • Enter the name of the Visual Studio Team Services account (i.e. https://account.example.com),

  • Enter the desired Visual Studio Team Services credentials.

    • Generate a Visual Studio Team Services Personal Access Token on the Visual Studio Team Services profile page ("Security" tab) granting at least the code read scope.

    • Create Jenkins credentials of type 'username/password credentials', the username will not be used, you can use your account name for triage

personal access token
Figure 9. Visual Studio Team Services - Profile Page - Personal Access Token
  • Once valid credentials are entered, the 'Repository' drop down list is populated with the list of available Git repositories

  • Select the desired repository

Once the project is saved, Jenkins indexes the Git repository and creates one sub-project per branch and per pull-request. Such a setup lets you get a dedicated build history per branch, or per pull-request, and adopt a branch based git development pipeline.

multibranch workflow job
Figure 10. Jenkins - Multibranch Pipeline Project - Sub Jobs