glaz666
glaz666

Reputation: 8731

Hudson: build chaining and two projects

I have two projects assembling in Hudson with Maven 2, say: Shared.jar and Server.jar.

Server is dependent on Shared.

I want to implement following build scenarios:

  1. When something is committed to Server - only Server is rebuilt.
  2. When something is committed to Shared - first Shared is built, then Server.
  3. When something is committed to Server and Shared (in one commit as they are in one SVN repo) - first Shared is built, then Server.

It is obvious behavior, but I what I get is I have Server built twice in 3rd case. Is there any opportunity to fix that? I am using Hudson 1.392

In SVN projects looks following:

+ SVN repo root
 |
 + Server
 |  ...
 |  pom.xml
 + Shared
    ...
    pom.xml

Upvotes: 1

Views: 329

Answers (1)

Jason Swager
Jason Swager

Reputation: 6501

I don't see an EASY way to do this, but I think there is a not-too-difficult way.

Create one new Job (call it TRIGGER for this example) that has a build trigger that monitors both Server and Shared. When something is committed (to either Server or Shared), have a build task (in my case, probably a Windows bat or a PowerShell script) that will check what is committed and decide what needs to be built - Server or Shared. Essentially, your three case logic would be handled here.

Based on the outcome, have the build task create/update two files in the workspace - call one of them BUILDSHARED.TXT and the other BUILDSERVER.TXT (for the example). You'll want to change the contents of the file (like dumping $BUILD_TAG into it) when you want that component to be rebuilt. NOTE: If you want to rebuild BOTH Server and Shared, you need to indicate that the Shared job should be rebuilt. Now, have the job archive those two files.

Modify your Shared job to include the URL Change Trigger plugin. Set the Build Trigger to monitor the URL of the permalink of the BUILDSHARED.TXT file of the TRIGGER job. When the file monitored is changed, a new build of Shared will be triggered.

Also modify your Shared job to start a down-stream build of the Server job upon successful completion. You can do that with the "Build other projects" option, or use something like my personal favorite, the Parameterized Trigger Plugin

Finally, modify your Server job to use the URL Change Trigger plugin too. Set it to monitor the URL of the permalink of the BUILDSERVER.TXT file of the TRIGGER job. Now, the Server job will be triggered if a Server commit is made or if the Shared job completes.

I think this does what you want...

Upvotes: 1

Related Questions