Crucial piece of puzzle when developing web application is Continuous Delivery. Testers or users can by early access to alpha version contribute to development process. Design, requirements, architecture or performance problems can be catched much sooner.
I am going to show how to set up this process with usage of Maven and Jenkins. Target environment is hosted on Tomcat7. Source code is hosted on GitHub. Because I am type of developer that tries to avoid polling as much as possible, I am going to show how to trigger this process by GitHub’s cool feature called WebHooks.
1. Create Continuous Delivery job
Creation of Jenkins job and integrating it with Maven is very easy. Will quickly cover this:
Create it with “New Item” -> ““
Set up GitHub URL in section “Source Code Management” (Authentication is not needed in my case, because my GitHub repository is public)
Skip section “Build Triggers” for now, will come back to this later.
Configure “Build” section with POM path and goals you are using for building your WAR file
Set up “Build Settings” -> “E-Mail Notification”
Save and try to run the Jenkins job. This is very common and basic Jenkins job configuration. Now we are about to set up deployment of WAR file into Tomcat7. But here comes dilemma into play. There are two very mature ways for deployment. I will cover both and let reader pick one.
a) Continuous Delivery with usage of tomcat7-maven-plugin
First of all we need to enable access into Tomcat7. Edit $CATALINA_HOME/conf/tomcat-users.xml (CATALINA_HOME is Tomcat’s home directory) and configure role and user as follows
Generate Personal access token in GitHub for Jenkins. This can be found under “Edit Your Profile” -> “Applications”
Set up GitHub plugin to use generated token in Jenkins. You can find this section in “Manage Jenkins” -> “Configure System” -> “GitHub Web Hook”. Note that you don’t need to use password. API URL is “https://api.github.com”
Create WebHook in Github. Open repository -> “Settings” -> “Webhooks & Services” -> “Create Webhook”
Use Jenkins URL with suffix “/github-webhook”. Jenkins will replace automatically as you configure jobs, so that it’s not needed to create GitHub hook for each Jenkins job
After creation you can test webhook via three dots in “Recent Deliveries”. HTML error code “302 Found” means that it’s working fine (even when GitHub highlights it with exclamation mark).
Finally enable GitHub triggering in Jenkins job
That’s it. Github commit should cause deploy into Tomcat now.
It is well known that RCP bundle is not the Maven’s best friend. Peacemaker between them is Maven’s plug-in Tycho. I was recently migrating my free time RCP based project into Maven Tycho. My goal was to share dependencies between normal Maven project and Tycho driven project. Plain maven project is needed for running TestNG tests (TestNG is not supported by Tycho).
There are two approaches how to automatically handle dependencies of Eclipse 4 RCP based project driven by Tycho:
manifest-first – this approach follows standard RCP/OSGi dependency mechanisms. All dependencies has to be also assembled into bundles. This is preferred and nicely described in tutorial suggested by Tycho’s website. It is hosted on github. But there are few problems complicating my goal:
It is needed to find existing bundle or create one for every dependency. Unhandy.
If I would use manifest-first approach, bundle dependencies wouldn’t be visible by non Tycho maven projects. I would need to have two set of dependencies. Redundancy.
pom-first – this is alternative approach when dependencies are packed into bundle by maven-bundle-plugin and this is used as dependency to project’s bundle. This approach is described here. Problem of this approach:
It is working only for Maven build and dependencies are not picked up by Eclipse.
Finally got the clue here (in the last approach) and came up with solution that is maybe not that pretty, but the dependencies are specified at one place and even Maven as well as Eclipse can pick them up. It is using some aspects both mentioned approaches.
I will show here only configuration crucial for my workaround. Whole project can be found on google code page. Let me describe maven projects structure:
discography-organizer.parent – contains various properties used by child poms. Is also used to run build of all sub-modules.
discography-organizer.dependencies.parent – shared dependencies are specified here
discography-organizer.dependencies.bundle – is doing two important steps:
And that’s it. Dependencies needed by main bundle or test artifacts are packed into jar files. This workaround has side effects that I really don’t like. Dependencies are ugly packed in one jar for main bundle. But I can live with that because this approach enables me to combine features of Tycho and non-Tycho maven plug-ins. I am planning to use another Tycho’s features (automatic building and JUnit plug-in tests) and I have good start point for it.
If you can think of some simpler or more elegant solution please don’t hesitate to comment it. Thanks