Configuring builds with Jenkins

The feature branch workflow requires a successful (green) build from Jenkins before you can merge the feature branch into the target branch in Helix TeamHub.

Initial setup

Perform the following steps for the initial setup:

  1. Set up a TeamHub project and create a new Git or Mercurial repository. You also need to have some feature branches to the Git/Mercurial repository.
  2. For Jenkins to execute the build, set up a Jenkins job to be triggered for the feature branches in this repository.
  3. For Jenkins to notify TeamHub of whether the build succeeded or failed, do the following:
    • a. Set up a TeamHub bot account for programmatic access.
    • b. Set up a TeamHub Jenkins hook for triggering the Jenkins build.
    • c. Configure the Jenkins job to build feature branches.
    • d. Install and configure Jenkins Helix TeamHub plugin.

1. Set up a bot account for programmatic access

Helix TeamHub has a unique concept called bot accounts, or simply bots. Bots are used for external access to Helix TeamHub APIs and version control systems. Configuring a continuous integration server is an ideal example of using bots instead of your personal credentials.

Setting up a bot account in TeamHub is done through the bots UI. All users with access to TeamHub can create bots. When you create a bot, you become the owner of the bot, but you can share ownership of bot accounts between multiple users. As the following figure shows, you do not need to assign others as owners or members of the bot, but simply add the bot to the project.

Managing bots in Helix TeamHub

To add a bot to a given project, you use the project's Team view. For this purpose, you need to assign a guest role to the bot because it only requires read access to the code. Bots with guest access can publish build events. For a complete description of bot credentials, see bots guide.

Bots in a project

2. Set up a Jenkins hook for triggering builds

Next, you need to set up a Jenkins hook for triggering a build for each change in the feature branches. You manage hooks in the project's Hooks view. Helix TeamHub supports over 80 hooks to different services. After you add the Jenkins hook to a Git repository, a commit hook posts a request to http://yourserver/git/notifyCommit after each change, in correspondence with Jenkins Git Plugin documentation.

Adding a Jenkins hook in Helix TeamHub

3. Configuring the Jenkins job

When setup on the TeamHub side is complete, you are ready to create a new job in Jenkins and configure necessary job-related settings. Perform the following steps:

  1. Add the clone URL for the repository to the job configuration. Helix TeamHub supports both SSH and HTTPS protocols for repository access and while SSH is typically preferred over HTTPS, in this example you use HTTPS for simplicity.
  2. Configure branches to build to refs/heads/features/**. This makes Jenkins run the job only upon changes to branches that are prefixed with features/, e.g. features/login, features/logging, features/foo, and so on.

    Jenkins job with Helix TeamHub Git repository configured

  3. Add your bot credentials to the configuration. In TeamHub, you can find them in the project's Team tab or in the company's Bots tab by clicking the cogwheel icon that appears when you hover over the bot name.

    Helix TeamHub Bot credentials

  4. Enable the Poll SCM option in the Job configuration for the TeamHub Jenkins hook to start the execution of this job. However, you do not need to specify a polling schedule. Jenkins relies on this setting to determine which builds to start when changes occur.

Setting up the build steps is not covered here because those steps are project specific. For more information on configuring the build and test automation, refer to the documentation for the application in question.

4. Configure the TeamHub Jenkins plugin

You install the TeamHub Jenkins plugin from the Jenkins plugin manager. Make sure to configure it according to the plugin instructions. When you are done installing and configuring the plugin, a new post build action should be available in the Jenkins job configuration named Helix TeamHub notification.

For Jenkins to send build information successfully, you need to add the Helix TeamHub notification post build action and configure the account key of the bot account to it. This way, the plugin utilizes the correct credentials when creating the event. After setting the post build action and saving the Jenkins job settings, you are all set for proper testing.

Testing the setup

You can now test the setup by creating a feature branch named features/new-feature. Create a couple of commits to the branch and push it to Helix TeamHub. Once the branch is pushed, you can create a new code review with the branch against the master branch and select the Require passing build check box.

Selecting the Require passing build check box disables merging the changes through the TeamHub web interface until TeamHub receives a successful build notification for the given branch. However, you can still merge changes manually through the command-line, which is sometimes useful.

Helix TeamHub new code review with passing build requirement

When you click the Create button in the New code review form to start the code review, you should see that the Build event is already green and that merging changes is possible. However, automated builds and verifications might take longer, and the successful or unsuccessful status only shows after the build is executed.

Helix TeamHub code review with successful build event

Updated on: 19 December 2017