One of the most important parts of the Hudson project configuration are the settings that connect your Hudson project to source control. Any software development project should be managed in a source control management system, many of which are open source software and have large user communities. Hudson has support for all common SCM systems as well as many of the less popular ones. Most likely you will find support for your SCM already installed or available as a plugin for installation in the Source Code Management section of available plugins in the plugin management as displayed in Figure 9.1, “The beginning of the list of Source Code Management plugins”. Read more about available plugins and their management in Section 5.2, “Available Plugins” in Chapter 5, Managing Hudson Plugins.
By default Hudson has support for Git, Subversion and CVS pre-installed. This chapter will document usage of the respective Hudson plugins as well as the plugin supporting the popular open source SCM system Mercurial.
Each of these plugins can be configured in the global Hudson configuration setting in its specific section added by the plugin.
After the global settings for the desired source management system are configured, you can configure the project-specific settings. Simply load the project’s configuration page and scroll down to the Source Code Management section. In this section, you must then select one of the radio buttons for the source code management system you are using as visible in Figure 9.2, “Selecting an SCM in the project configuration”
After this selection you will be able to configure the parameters specific to the selected SCM and the current project.
The Subversion Plugin for Hudson and therefore support for the popular Subversion SCM system is part of the default install of Hudson. It is therefore not necessary to perform any further plugin installation to use Subversion for your project.
In order to use Subversion successfully, you need to set up the global configuration in the Hudson Server configuration screen displayed in Figure 9.3, “Global Subversion Configuration”.
The following parameters need to be configured as desired:
Queue time
, which will cause a
build to be run off the revision present in the repository when the
job is added to the Hudson build queue. The Build time
policy one
the other hand will use the revision in the repository found when
the build actually starts . The Head revision
policy will use the
HEAD revision in the repository. Finally these settings are
overridden if a revision is specified in the subversion URL or as a
revision parameter in a parameterized build.
$
character.
Selecting Subversion under the Source Code Management section will display the configuration options shown in Figure 9.4, “Configuring project-specific Subversion settings”. Clicking on the Advanced button will reveal the advanced configuration parameters shown in Figure 9.5, “Configuring advanced project-specific Subversion settings”.
The following parameters can be configured:
@number
as well
as subversion keywords for revisions and dates. The link Update
credentials navigates you to the SVN authentication screen documented
below.
If you are checking out more than one Subversion module, you can also supply a Local module directory that Hudson will check out the specified module to. If you leave the Local module directory blank, Hudson will check out the specific module to the root of the project’s workspace.
The Repository depth option allows you to specify the depth for the checkout of this module, with the default being+infinity+, which means that all nested directories of the repository will be checked out. This is useful to limit the size and scope of your checkout.
You can add a new module with the Add more locations button and remove it with the Delete button.
The default value of Use svn update as much as possible will cause the least load on the Subversion server by only issuing an update command on top of the existing checkout in the project workspace.
The option Use svn update as much as possible, with svn revert before update will do minor cleanup of the workspace by reverting any local modifications.
The option Emulate clean checkout by first deleting unversioned/ignored files, then svn update provides a good compromise between performance and thoroughness, since it closely resembles a clean checkout without the performance and load implications for the Subversion server as well as Hudson.
Finally the option Always check out a fresh copy will delete the workspace content and perform a fresh checkout for each build. Choosing this option should be considered carefully since it can put a significant load on the Subversion and Hudson servers.
You can navigate to the Subversion Authentication screen by clicking the Update credentials link, which will display as visible in Figure 9.6, “Configuring subversion authentication Subversion settings”.
The subversion plugin can be configured to use authentication with:
By default the above configuration will override any global configuration. This behaviour can be deactivated by selecting no in the Override global credentials option.
Beyond these basic configuration options the Subversion plugin supports advanced options to provide more parameters to your Subversion commands used for the build.
Both parameters support usage of regular expression patterns to specify the desired files as well as multiple lines to configure larger sets of files and directories to match.
In order to build a project controlled in subversion you only need to configure the repository URL in the project configuration using an URL available for anonymous read access to the repository.
The subversion plugin exports the following environment variables for your usage in build scripts and others:
If multiple modules are defined these environment variables get and
index appended in to their names and all revisions and URLs of the
modules will be exported as SVN_REVISION_1
, SVN_REVISION_2
,
SVN_REVISION_n
and SVN_URL_1
, SVN_URL_2
, SVN_URL_n
.
Git is the most successful, modern distributed version control system and has gained wide acceptance in the open source community and beyond. and repository hosting services available from multiple suppliers for commercial and open source usage.
The Hudson Git Plugin and therefore support for Git is available in default Hudson installs from version 2.1 onwards. If it is not installed in your Hudson instance, simply find the plugin in the Source Code Management section of the available plugins and install it like any other plugins as documented in Chapter 5, Managing Hudson Plugins.
The global configuration for using Git is set up in the Git section of the Hudson Server configuration screen as displayed in Figure 9.7, “Configuring Git Installations”.
git
. Otherwise an absolute path can be used as well.
In addition to using an already installed git, the Git plugin
facilitates the tool installer from Hudson that allows Run Command and
Extract from *.zip/*.tar.gz
based installs similar to the JDK
installs documented in details in Section 3.3, “Configuring JDK Installations”. The Ant
and the Maven plugins installers described in
Section 3.4, “Configuring Ant Installations” and Section 3.5, “Configuring Maven Installations” use the same
installers and you can find more hints of its usage there.
A further global configuration for git can be done in the Git plugin section displayed in Figure 9.8, “Configuring Git user name and email values”. Specifying Global Config user.name Value and Global Config user.email Value values will cause the plugin to issue git config commands setting these options for each project that is configured to use git. The specific project configuration allows you to override these setting for each project individually.
Once you have configured Git in the global Hudson configuration you can configure project-specific Git settings. Selecting Git under the Source Code Management section of your project configuration will display the configuration options shown in Figure 9.9, “Basic Git source control information”.
The section shown in Figure 9.9, “Basic Git source control information” contains the following options for the basic configuration of git in your project configuration:
http://
, ssh://
and
git://
are all supported. Advanced configuration as displayed in
Figure 9.10, “Configuring repository specific Git configuration” allows you to provide a
name of the repository as well as a refspec. Providing multiple
repositories only makes sense when they are clones or instances off
the same repository, since they will be used for merging together
the content prior to the build.
A common configuration would be to specify the main branch in the
repository e.g. master
. This would ensure that the build is only
triggered for changes committed to master. If you want to have other
branches built as well it is advisable to create separate Hudson
projects for the different branches.
The advanced usage of this feature would be to specify multiple branches. These branches would be used for a merge prior to a build and could be configured to push the merge result back to the remote repository after a successful build.
In many use cases you will be able to configure everything necessary with regards to git using the basic configuration options documented above. For more complex cases the plugin provides various advanced parameters as displayed in Figure 9.11, “Configuring advanced Git configuration”, which become accessible by pressing the Advanced button and documented below.ex
user.name
property
prior to checkout and build. It overrides the global git
configuration of the same property
user.email
property
prior to checkout and build. It overrides the global git
configuration of the same property
author
, rather than the default committer
.
The git plugin adds the post build action Git Publisher as displayed in Figure 9.13, “Configuring Git Publisher options” to the project-specific configuration. It can be used to push merges done prior to the build back out to a remote repository after a build.
When configuring the Git Publisher you can specify Tags in fields displayed in Figure 9.14, “Configuring Tags for Git Publisher”.
In order to build a project controlled in git you need to have a git installation configured in the global configuration.
In terms of project specific configuration you only need to specify the public URL of the repository. We recommend to specify the branch to build as well since the default setup without a branch specified will examine all branches in the repository and build the latest changed branch. In a normal project this might adversely affect the stability of the build and potentially cause a confusing history for the project. We suggest to set up separate projects for each branch you want to track and build on Hudson.
The recommended basic usage with the git plugin is to configure the
project branch for the build e.g. master
, which will be
automatically configured if the field is left blank. Alternative you
can specify a different branch name or use **
. This option causes
all branches to be monitored for changes and the branch with the last
changes will be built.
This will cause your project build history to be comprised of builds from all the different branches individually in the order of changes received and potentially even omit builds if changes hit multiple branches between builds.
However together with configuring Merge Options it allows for a
automated merge from whichever branch to have the latest changes to
the target branch e.g. master
and proceed with the build after the
merge.
Now you can activate the Git Publisher post-build action Push Only If Build Succeeds and Merge Results to have the remote repository updated with the successful merge results.
This approach can be configured with specific branches rather than the default empty specification of branches to have better control of the source branches to merge from. It can also be combined with multiple repositories to pull changes in from.
Mercurial, also known as hg, is a successful, modern distributed version control system and has gained wide acceptance in the open source community and beyond used for large projects like OpenJDK and Netbeans and repository hosting services available from multiple suppliers for commercial and open source usage.
The Hudson Mercurial Plugin and therefore support for Mercurial needs to be installed on your Hudson instance. Simply find the plugin in the Source Code Management section of the available plugins and install it like any other plugins as documented in Chapter 5, Managing Hudson Plugins.
To configure Mercurial, find the Mercurial section in the Hudson Server configuration screen as displayed in Figure 9.16, “Configuring Mercurial Installations”, press the Add and configure the parameters for your Mercurial install. If Mercurial is already installed on your Hudson server and the hg is available on the path, you do not need to configure a Mercurial installation. The plugin will pick up the installed version.
hg
executable. The field is
pre-filled with INSTALLATION/bin/hg
, which is the correct value if
you use a manual install of hg. If you are using binary package as
provided by your operating system package management system the
correct value is likely just hg
, since the command would be on the
PATH
. Another common option is the absolute path of the executable
e.g. /usr/bin/hg
.
In addition, the Mercurial plugin facilitates the tool installer from
Hudson that allows Run Command
and Extract from *.zip/*.tar.gz
based
installs similar to the JDK installs documented in details in
Section 3.3, “Configuring JDK Installations”. The Ant and the Maven plugins installers
described in Section 3.4, “Configuring Ant Installations” and Section 3.5, “Configuring Maven Installations”
use the same installers and you can find more hints of its usage
there.
Selecting Mercurial under the Source Code Management section will display the configuration options shown in Figure 9.17, “Configuring Mercurial Source Control Information”.
The section show in Figure 9.17, “Configuring Mercurial Source Control Information” contains the following options:
default
will be checked out for the
project build. This input allows you to specify and therefore build
any other branch.
In order to build a project controlled in Mercurial you need to install the Mercurial plugin and have a hg installation configured in the global configuration.
In terms of project specific configuration you only need to specify the public URL of the repository.
If your Hudson Jobs rely on CVS there is no plugin configuration necessary, as the Hudson CVS Plugin and support for the CVS system is included as a part of the default Hudson distribution.
To configure CVS, find the CVS section in the Hudson Server configuration screen as displayed in Figure 9.18, “Global CVS Configuration”. From the Hudson start page, click on Manage Hudson, then click on Configure System, and scroll down to the CVS section of this configuration form. If CVS is already installed on your Hudson server and the cvs is available on the path, you do not need to configure a CVS installation. The plugin will pick up the installed version.
The CVS configuration section allows you to configure the following properties:
Selecting CVS under the Source Code Management section will display the configuration options shown in Figure 9.19, “Configuring CVS Source Control Information”.
The section show in Figure 9.19, “Configuring CVS Source Control Information” and Figure 9.20, “Configuring CVS Source Control Information” contain the following options:
<protocol>:<user>:<password>@<servername>:<serverpath>
Each component in the CVSROOT parameter
:local:
for local or net file
system level connection, :pserver:
as the standard unsecured
protocol, :ext:
, :ssh:
and :extssh:
for secure shell based
connections and :sspi:
for Windows based access.
Due to concurrency and additional load on the repository, we recommend avoiding the local protocol for CI builds. Using the local protocol in Hudson often results in problems if too many clients are trying to access a CVS repository at the same time.
Please also keep in mind that the pserver protocol is insecure. If you storing sensitive data or code in a CVS repository, avoid the pserver protocol and use ssh as an alternative.
:pserver:
or :sspi:
protocol.
@
is required at
the beginning of the server name.
:
. The path
itself can be either unix style like /opt/data/cvsrepo
or Windows
style like C:\cvs\repository
.
An example for a valid URL with a module is shown below.
:pserver:[email protected]:/cvsroot/tortoisecvs