This document describes building and testing Subversion plugin for Jenkins.
Jenkins plugins are built normally using Maven. However, there is also a special process for running a plugin.
Note: HPI = Hudson Plugin Interface.
Table of contents:
- (1) Building the plugin
- (2) Testing
- (3) Clean up after testing
- Adding automated tests
- Debug an automated test
- Summary
Building should be possible both on Windows and Linux. You only need Maven and Java installed.
You should build with JDK LTS for testing. See: https://en.wikipedia.org/wiki/Java_version_history#Release_table
Create __setup_env.priv.sh with your Java and Maven paths.
See more in: __setup_env.example.sh.
Building without tests from bash (or Git bash):
build-only.shThe main artifact is:
target/subversion.hpi
build-full.shYou can run a local Jenkins instance with the local Subversion build. This is the best option for development.
build-run-local.shThis should only take a few minutes. When the log becomes idle open: http://localhost:8080/jenkins/
The working directory will be the ./work/ subdirectory.
To terminate the Jenkins instance use CTRL+C in the shell window.
Copy the file:
target/subversion.hpi
to:
$JENKINS_HOME/plugins/
Restart Jenkins.
If you modified an existing Jenkins instance you should remove the plugin after testing.
So after testing, remove:
$JENKINS_HOME/plugins/subversion/
(the unpacked plugin directory)
This should force the plugin to be reinstalled.
However, in most cases it is probably better to stick to running a test Jenkins instance (mvn hpi:run).
Files like svn-externals.zip are in the resources directory.
Example of creating a test job:
File testRepo = new CopyExisting(getClass().getResource("svn-externals.zip")).allocate();
String repoUrl = "file://" + testRepo.toURI().toURL().getPath() + "repo/trunk";
String localPath = "repo-dir";
SubversionSCM scm = new SubversionSCM(repoUrl, localPath);The function testRepo.toURI().toURL().getPath() will return a path like
/target/tmp/j%20h1849784217265900740 (which will be the root of the ZIP file).
In the example above repo is a directory in the ZIP file which contains things like: svn.ico, conf/, db/.
And trunk is a path to a directory in the SVN repo (URI).
To make an svn checkout, just run the build (create an example project and build it):
FreeStyleProject p = r.createFreeStyleProject();
p.setScm(scm);
var b = p.scheduleBuild2(0).get();To run or debug a single test, you might want to use NetBeans.
- Open the project in NetBeans.
- Open a test file, e.g.
src/test/java/hudson/scm/SubversionSCMTest.java. - Scroll to a test, e.g.
workspaceVersionAndExternalFiles(). - Use the play icon (▶) to run or debug the test.
- Dev build →
mvn clean install -DskipTestsXORbuild-only.sh. - Automatic tests →
mvn clean installXORbuild-full.sh. - Dev test →
mvn hpi:runXORbuild-run-local.sh. Recommended for acceptance tests. - Manual test → copy the
subversion.hpifile toplugins/and restart Jenkins. Not recommended unless you need to test in a very specific environment.