How do I capture the Maven Jar name as a part of a Hudson job?

I have a Maven 3 job configured in my Hudson server.

When the Hudson server successfully builds the Maven jar, I have the jar being deployed to an SCP repository on another server.

I want to execute a relink.sh script on the remote host where one of the parameters is the name of the newly delivered jar file (e.g. /usr/bin/relink.sh myproject-0.0.2-SNAPSHOT.jar).

How do I get that Maven-based file / version name into a variable that I can then use in my Hudson call to execute the remote script?

Answer

I’m not sure if you can or can’t pass the variable, but a work-around would be to first copy the file to a staging directory, instead of directly to where you want it to go. Then have your script look in the staging directory for a file and move it:

STAGE_DIR=/path/to/stage
DEST_DIR=/path/to/dest
LINK=/path/to/link.jar

while read file; do
    mv $file $DEST_DIR
    ln -s -f $DEST_DIR/$(basename $file) $LINK
done < <( find $STAGE_DIR -name "myproject*SNAPSHOT.jar" )

You might want to do some error checking and exit with non-0 if there is, e.g., more than one file that matches, no files, etc. Have you solved the issue?

Attribution
Source : Link , Question Author : Lorin S. , Answer Author : zerodiff

Leave a Comment