views:

441

answers:

6

Hi,

I am trying to figure out how to setup continuous integration using maven.

What I want is:

  1. Check for new stuff in SVN
  2. If changes are detected, check them out
  3. Build and deploy

I think all of this can be pushed into some shell script to make it be invoked by cron. Thus we will have automated continuous integration (nightly builds, for example)

I know that maven has SCM plugin for working with version control systems, but I don't know how to make it check for changes in repository and based on the results launch checkout.

So I am asking the audience :)

PS I forget to mention - I am NOT INTERESTING in any of existing applications! They are too heavy for my VPS server. Please do not advise them

A: 

Download and install JetBrains TeamCity - the Professional edition is free. It is a superb continuous integration server that supports SVN and Maven (amongst other things).

David M
+1  A: 

Maven is a repository for storing code and building projects. Personally I wouldn't use it as a continuous integration tool.

Take a look at hudson, and I think you'll find more what you're looking for. Other continuous build tools will work for you as well. It will work by getting the latest version of your code from your repository, and building it on any schedule you want (or even a non-scheduled manual build).

Kieveli
+3  A: 

Take a look at Hudson. It's free, open-source, actively developed, has dozens of useful plugins, has great Maven2 support, and is all around awesome.

It's also frequently discussed on Stack Overflow.

matt b
+1  A: 

Have you looked at hudson?

sbi
A: 

We use an application called Luntbuild to manage everthing like that.

  • First you make a project
  • Point to ant, maven or some other builder you're using (We just use ant-scripts)
  • Define an SVN adapter (or other VCS)

Then the application monitors SVN for changes and builds/deploys your apps...

Tommy
+1  A: 

I'd recommend using a recognised CI tool for managing this as there is more to CI than just the build.

But if you are determined to roll your own, you can use some of the goals from the maven-scm-plugin and capture the output.

Assuming you have a local copy of the project so you've access to the pom, you can run the status command to check for changes, and parse the output checking for any changes The goal to use is:

mvn scm:status

If you see any changed files, then you can check out the changes and invoke your build. Beware though, there is a bug in maven-scm-provider-svnlink text that means changed files can be skipped! You may be better invoking Subversion directly and parsing its output.

For example the following will clear up a previous build, check out any changed content and then run the deploy goal.

mvn clean scm:checkout deploy

If you don't have a working copy of the project, you can use the scm:bootstrap goal to obtain it. If you set up some properties in a pom you can reuse the pom to bootstrap multiple projects.

For example the pom below can bootstrap any project if you pass the appropriate command line arguments to it:

mvn scm:bootstrap -DscmUserName=me -DscmPassword=mypass -DscmConnectionUrl=scm:svn:http://myserver/myproject/trunk

<project>
  [...]
  <packaging>jar</packaging>
  <version>0.0.1</version>
  <name>SCM bootstrapper</name>
  <url>http://somecompany.com&lt;/url&gt;
  <scm>
    <connection>${scmConnectionUrl}</connection>
    <developerConnection>${scmDeveloperConnectionUrl}</developerConnection>
    <url>${scmUrl}</url>
  <scm>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <goals>install</goals>
          <username>${scmUsername}</username>
          <password>${scmPassword}</password>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
  <properties>
    <scmDeveloperConnectionUrl>dummy</scmDeveloperConnectionUrl>
    <scmConnectionUrl>dummy</scmConnectionUrl>
    <scmUrl>dummy</scmUrl>
    <scmUsername>dummy</scmUsername>
    <scmPassword>dummy</scmPassword>
  </properties>
</project>

To make Maven work with subversion you need to configure the scm section of the POM:

<scm>
  <connection>scm:svn:http://path/to/project&lt;/connection&gt;
  <developerConnection>scm:svn:http://path/to/project/tags/version&lt;/developerConnection&gt;
  <url>scm:svn:http://path/to/project/tags/version&lt;/url&gt;
</scm>


As an alternative for polling for changes, consider adding a hook to subversion so that the build is triggered when a change is made. There's another question that can give you a pointer on doing that.

Rich Seller
>>If you see any changed filesThat is the main point I would like to automate :) May be due to the bug you have mentioned, I can't figure out how to do that. So I came to conclusion that probably it will be easier to user 'svn update' command and, as you told, parse the output in shell script to detect incoming changes.So thanks for that!
glaz666
I added a bit to the end on using Subversion hooks to trigger your build, though frequent commits could start causing problems with this approach unless you implement a queue or a flag to check for current builds.
Rich Seller
super, hooks can work! thanx!
glaz666