Structure101 Build (for Java, .Net and more) can be invoked in Hudson/Jenkins via an Ant, Maven or Execute Shell Script build step. In this post I will show example use cases of how to use each build step, and how to make a Hudson/Jenkins build unstable if any architecture violation is found. Thanks to Rochelle Raccah at eBay for helping me figure this out.
First you will need to configure Hudson/Jenkins to use the Text Finder Plugin by installing this plugin. This plugin will then be used to find text generated by Structure101 build on the CI’s build console, and based on this text the Hudson/Jenkins build can be made unstable.
Tests have been carried out on Hudson 1.398, 2.1.2 and Jenkins 1.440.
Before demonstrating how to do the Hudson/Jenkins integration, I’ll give a brief overview of the Structure101 Headless Utility. Structure101 Headless is the interface between the build tool and the Structure101 Repository that enables the piping of command-line operations, each operation having a specific task. Structure101 Headless can be executed from the command line, e.g.
java -Xmx256m -classpath structure101-java-bxxx.jar com.headway.assemblies.seaview.headless.S101Headless continous-build-config.xml
In the above command line, the continuous-build-config.xml file defines the operations we wish to perform using Structure101 Headless. Each operation takes some arguments, which can be mandatory input, and details about these arguments, and their meaning, can be found here.
The xml file has the following structure:
<?xml version="1.0" encoding="UTF-8"?>
Within the operations tag we define the operations we wish to perform.
For the purpose of this blog we will focus on the check-architecture operation.
Typically, this operation breaks the build if any Architecture Violation is found. But in some environments it may not be desirable to break the build whenever a (new) architecture violation is discovered, but instead just flag the build as unstable (the build with a yellow dot).
As an example, I have included a configuration file continuous-build-config.xml with this blog. This configuration file defines one operation (check-architecture) with its relevant arguments.
Now that we’ve had a basic introduction to Structure101 Headless, I will talk about how to invoke these two operations in Hudson/Jenkins.
Using Structure101 Headless via Ant in Hudson/Jenkins
This involves the following steps:
- Create your xml configuration file (continuous-build-config.xml) and save it to a convenient location (say C:myconvenient-location continuous-build-config.xml).
- Create a target in your Ant build file as shown below (note, ensure failonerroris false or else your build will fail):
<target name="Check-Architecture" description="Check Architecture snapshot">
<java classname="com.headway.assemblies.seaview.S101Publisher" fork="true" failonerror="false" maxmemory="256m" dir="C:/Program Files/Structure101/java">
<arg value=" C:myconvenient-location continuous-build-config.xml "/>
- In Hudson/Jenkins create a new build step “Invoke Ant” as shown below:
- Next configure the Text Finder Plugin as shown below (note the regular expression is Structure101 violations, and that both “Allow search the console output” and “Unstable if found” are ticked):
- Save, hit build now, and you will see the unstable build:
Using Structure101 Headless via Maven in Hudson/Jenkins
Using the Structure101 Maven Plugin we can make the Hudson/Jenkins build unstable if (new) architecture violations are found. First we define the check-architecture goal in our pom.xml and their relevant configurations.
I have included a sample pom.xml at the bottom of this blog, and make sure you have set the following two values to false, otherwise the build will be flagged as failed:
The following steps are involved in configuring Hudson/Jenkins for Maven:
- Configure your pom.xml to use check-architecture goal, see attached pom.xml as an example.
- Create the build step in Hudson/Jenkins “Invoke Maven 3” as shown below
- Configure the Text Finder Plugin as shown below (note the regular expression is Structure101 violations, and that both “Allow search the console output” and “Unstable if found” are ticked
- Save, hit the build now link, and you will see the unstable build:
Using Structure101 Headless via Windows batch command in Hudson/Jenkins
For this, the following steps are involved:
- Create xml configuration file (continuous-build-config.xml) and save it to a convenient location (say C:myconvenient-location continuous-build-config.xml).
- In Hudson/Jenkins create a new build step as shown below
Optionally, you can also wrap the command above and use a batch file(included with this blog) as shown below
- Configure the Text Finder Plugin as shown below (note the regular expression is Structure101 violations, and that both “Allow search the console output” and “Unstable if found” are ticked):
- Save the configuration, hit build now, and you will get an unstable build