19 June 2009

Hudson, Maven and SVN Credentials

I figured out today how to better configure it so a Maven build running on Hudson would be able to access SVN with a user.
  • Hudson - Continuous integration build server http://hudson.dev.java.net

  • Maven - Build tool for Java applications (among others) http://maven.apache.org/

  • SVN - Subversion is a source code repository used to store source code (and what-not) and keep all the various versions created while the software is developed and maintained. http://subversion.tigris.org/ (I use the version from http://www.collab.net/ where you can get binaries for Windows, Linux MacOS and Solaris.)
I'm in the process of moving things from Continuum (another CI build server) to Hudson and still evaluating things.

This all started when I added a build job to Hudson for a library we use internally here where I work. This new Logger project holds some add-on things to use with Log4j.

When I started, the other day, putting jobs in, I entered the SVN repo URL for Hudson to use when it updates its workspace copy of the source code. When I moved the cursor off the URL box, Hudson complained that it couldn't use that repository and suggested that I enter user credentials. I entered my personal login and password and hurried on. I was trying to get something to build on this CI server I was testing.

The other builds worked. When I added the Logger job, it failed when trying to do Maven's Change Log report. Here is the error:
[INFO] Generating "Change Log" report.
[INFO] Generating changed sets xml to: /hudson/jobs/Logger/workspace/Logger/target/changelog.xml
[INFO] Executing: svn --non-interactive log -v -r "{2009-05-19 19:45:12 +0000}:{2009-06-19 19:45:12 +0000}" http://svn.flatland.com/repos/trunk/base/Logger/
[INFO] Working directory: /hudson/jobs/Logger/workspace/Logger
[ERROR] Provider message:
[ERROR] The svn command failed.
[ERROR] Command output:
[ERROR] svn: error: cannot set LC_ALL locale
svn: error: environment variable LANG is en_US.UTF-8
svn: error: please check that your locale name is correct
Now, after a whole bunch of googling I came to the conclusion that I needed to update the Subversion command line client version from 1.3.? to a newer version. The current version on Collabnet's site is 1.6.? so I downloaded it, uninstalled the old one and installed the new one. (The server is Red Hat Linux 4.? so this was all done with RPM commands and changing some environment variables and the path.)

Ok ... cool. Now that error is gone. I build and ...

[INFO] Generating "Change Log" report.
[INFO] Generating changed sets xml to: hudson/jobs/Logger/workspace/Logger/target/changelog.xml
[INFO] Executing: svn --non-interactive log -v -r "{2009-05-20 16:42:57 +0000}:{2009-06-20 16:42:57 +0000}" http://svn.flatland.com/repos/trunk/base/Logger/
[INFO] Working directory: /hudson/jobs/Logger/workspace/Logger
[ERROR] Provider message:
[ERROR] The svn command failed.
[ERROR] Command output:
[ERROR] svn: OPTIONS of 'http://svn.flatland.com/repos/trunk/base/Logger': authorization failed: Could not authenticate to server: rejected Basic challenge (http://svn.flatland.com)
Now, I'm not getting the right credentials to SVN.

It turns out that there are two places where credentials are stored in this case.
  1. Hudson has credentials that it uses when updating the source code prior to a build. It also uses it to check whether a build is needed if you check that box.

  2. Maven has credentials that is uses when it is accessing SVN.
I decided to just set up a new credential for Hudson to use with SVN. So I went over to the SVN server and added a new user, "hudson", and gave him permission to read and write to the interesting parts of the repo.

Then I had to go into Hudson, select the Logger job, select to configure, scroll down to the SVN repo URL and click the little help icon to the right of it. It is a blue circle with a tiny question mark in the middle. Inside the message there is link in the 2nd paragraph where it says, "If you already have a working credential but would like to change it for other reasons, click this link and specify different credential." Click the words "this link".

This brings up a new page where you can enter the first part of a URL for the SVN repo. I enter "http://svn.flatland.com/repos/trunk" but I could have added "Logger" on the end to only apply to this project's code. Then I selected the top radio button and entered the new user name (hudson) and password (think again). Clinking OK saved that away somewhere within the depths of Hudson. I don't know if there is a way to see all the ones that have been set and delete of update them.

Now, there is one more part of this. Or is it two parts that work together.

I have a part in the pom.xml for this project that tells where Subversion is. It's in the <scm> section in the pom and looks like this. I didn't have to change it but I did have to look at it to see what was in there. This tells Maven where the repo is. It gets used in several ways.
<scm>
<connection>scm:svn:http://svn.flatland.com/repos/trunk/base/Logger/</connection>
<developerconnection>
scm:svn:http://svn.flatland.com/repos/trunk/base/Logger
</developerconnection>
<url></url>
</scm>
And I have to put something in the settings.xml file on the build server. It is in ~/.m2/settings.xml for the user that Hudson runs under on the build server. In my case that is /home/hudson/.m2/settings.xml. Then I add a new bit of credential that looks like this:
<settings>
...
<servers>
... other server tags ...
<server>
<id>svn.flatland.com</id>
<username>hudson</username>
<password>password</password>
</server>
</servers>
...
</settings>
Save that and the buld now works.
[INFO] Generating "Change Log" report.
[INFO] Generating changed sets xml to: /hudson/jobs/Logger/workspace/Logger/target/changelog.xml
[INFO] Executing: svn --username hudson --password ***** --non-interactive log -v -r "{2009-05-20 17:27:23 +0000}:{2009-06-20 17:27:23 +0000}" http://svn.flatland.com/repos//trunk/base/Logger/
[INFO] Working directory: /hudson/jobs/Logger/workspace/Logger
[INFO] Generating "Developer Activity" report.
[INFO] Using existing changelog.xml...
[INFO] Generating "File Activity" report.
[INFO] Using existing changelog.xml...
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

BTW, I'm using Hudson 1.309 version.

-- Lee Meador

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete