Showing posts with label Hudson. Show all posts
Showing posts with label Hudson. Show all posts

25 February 2010

Auto-Install Maven into Hudson

It turns out to be easy to have Hudson download a version of Maven for you to use in your builds.I Googled for instructions and found none but then any Google for anything about Hudson is likely to find the river, the explorer or Jennifer.

I'm using Hudson 1.336 as I write.

You may need to figure out how to set up a proxy if your Hudson server is inside your companies network boundaries. The following instructions assume you have already got that working. I find the whole proxy issue confusing as there is a way documented to enter a proxy when deploying to a repository and a way to enter a proxy that is sort of hidden when updating plugins. I haven't seen one related to downloading tools.

1) Click on the "Manage Hudson" link on the top page.
2) Click on the "Configure System" link at the top of the list in the main part of the page.
3) Scroll Down to the "Maven" section and click the "add Maven button" as in the red circle below
4) Select "Add Installer"
5) The drop down list of install from options has an option "tar.gz" you should select.
6) "Label" field is blank. I don't know quite what this does.
7) Enter a link to one of the apache mirrors like: "http://mirror.uoregon.edu/apache/maven/binaries/apache-maven-2.2.1-bin.tar.gz" but you can pick your own mirror by opening another browser tab and going to "http://maven.apache.org/download.html" and clicking on the link for the tar.gz file in the "mirrors" column. I picked the one at the top of the top section on that page but you may want a not-latest version. That takes you to the page where it allows picking a mirror. Copy one of the mirror links for the site close to you. The link above is the one I picked.
8) The subdirectory will be like "apache-maven-2.2.1" with the main folder name from the tar.gz file you pointed to. Note that older versions of Maven (for example 2.0.7) are like "maven-2.0.7" and newer ones add the word "apache" to the front. This subdirectory is added to the root folder of where-ever Hudson puts tools that it downloads to produce the MAVEN_HOME value Hudson passes to Maven for builds using this Maven version.
9) Save the configuration changes with the button at the very bottom of the page (or just hit 'enter').

At this point in the process, I was left wondering when it would get downloaded and installed.

10) Create or edit an M2 build to use the new Maven version you just added. When it first runs, the tool will be added to a "tools/maven" folder inside your hudson folder structure AND THEN the build will kick off. (This might work with some other type of build but I haven't tried it.)

01 December 2009

Hudson updates, Linux and the corporate proxy

My Hudson build server is running on Red Hat Linux. This became important when I figured out that I couldn't update Hudson automatically because of some sort of proxy problem.

I would select Manage Hudson > Manage Plugins and then select a plugin or two to update and click the "Install" button to do it. It would give me an error "NoRouteToHost" and show a Java stack trace.

First Try

I was running Hudson 1.309 and, though it might be a bug in that version (but don't quote me on that), entering the corporate proxy server's IP and port on the "advanced" tab of that "Manage Plugins" page didn't fix the problem. (There was a wierd bug where, if I used FireFox 3 to enter the proxy info, it would default the user and password to those I used to log into Hudson. This didn't happen on IE 6.)

This seemed to make no difference at all. The same error popped up as before.

Second Try

I use the command line to start Hudson. Its a command like "java -jar ..." with a zillion options included. So I added "-Dhttp.proxyHost= and -Dhttp.proxyPort=" to the command line.

This had a different result. The plugin upload would work but Hudson could no longer access my Subversion server. The error message appeared in the console log when a job would run but it still said "No route to host".

Third Try

Well, I thought, I will need to exclude the Subversion server from Java's proxy information. This should have worked by adding "-Dhttp.nonProxyHosts=*.domain.com" to the command line.

This didn't work either. I don't know why not but the errors were the same as in the 2nd try.

I took all that stuff off the command line.

Fourth Try

Now, I though, isn't there some way to tell Linux about a proxy to use by adding an environment variable of some sort. I had to Google around to find it. You add an entry to the environment with a command like "export HTTP_PROXY=http://proxy.domain.com:8080/" if you are just typing. I left off the "export" part for the shell script that starts Hudson running.

This worked. Things would update inside Hudson. The jobs can get to the Subversion server. All seems to be cool now.

Disclaimer

I don't claim to know why the last method worked. I don't know if it would work the same way if I was using Tomcat to run the hudson.war. I don't know if the "advanced" tab's proxy settings work better in a later release of Hudson.

All this ignorance on my part bothers me. But, for now, I'm just happy it works.

-- Lee

19 June 2009

Hudson, Maven and Nexus Credentials

I decided to figure out how to post my Logger project from Hudson to Nexus.

Outline this time (I'm in a hurry)

* Go to Nexus which, in my case, is http://nexus.flatland.com:8090/nexus.
* Login as Admin
* Click "user" in the left sidebar
* Click add a user in the top of the main window
* I added one called 'hudson'.
* I gave it two permissions. 'Nexus Deployment Role' and 'Repo: All repositories (full control'
* It has to be active but the other fields are self-evident.
* Save the changes.

Now you have to make sure the repo can be deployed to:

* Still logged into Nexus as Admin.
* Click "Repositories" in the left sidebar.
* Choose 'releases' at the top (or 'snapshots' if you want to deploy a snapshot)
* Choose the 'configuration' tab
* Maybe you scroll down, maybe not, but get to the "Allow deployments" entry and make sure it is 'true'.
* If you changed it, you have to 'save' the result.

On the build server you will need to edit settings.xml to add credentials for Hudson to use with Nexus. On my Red Hat Linux server it is in ~/.m2/settings.xml (/home/hudson/.m2/settings.xml on my server).

This should go into the settings.xml file. It goes in the <servers> section.

<server>
<id>nexus.flatland.com</id>
<username>hudson</username>
<password>password</password>
</server>

Now Nexus will let the 'hudson' user deploy something.

* Go to Hudson.
* Select the Logging job.
* Click on one of the builds in the list of builds at the bottom of the left sidebar. (Usually you will want to pick the most recent build but older ones will let you restore something older.)
* Click "Redeploy Artifacts" among the left sidebar options. It has a green curvy arrow icon.
* Enter (or use the down arrow to get the list) the Nexus repo URL. It will look something like this: http://nexus.flatland.com:8090/nexus/content/repositories/releases (but use 'snapshots' instead of 'releases' if you are deploying a snapshot). The host name is the same as the Nexus server that I messed with above.
* Click 'advanced' on the right side of the screen.
* Enter 'nexus' for the id.
* Click 'ok' and it should deploy.

Note that all the 'artifacts' created with the Maven build will be deployed. This might include 'sources', 'test-jar' and 'test-sources'. Adding the 'test-jar' is done with an option on the maven jar plugin. The other two are don with options on the maven sources plugin.

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