0

A sample filename is Sample-0.0.1-SNAPSHOT.jar (result of a maven build in jenkins).

My goal is to run a shell script that executes on failure and what that script does it adds incremental numbers to the filename.

So lets say something like Sample-0.0.1-1-SNAPSHOT.jar, Sample-0.0.1-2-SNAPSHOT.jar.. etc.

(BTW: In order to produce the filename, Jenkins uses the following format for environment variables to fetch the related info from the POM file: $POM_ARTIFACTID-$POM-VERSION.jar)

I was thinking somehow using $POM-VERSION to echo it out and use sed to add/replace the incremental numbers?

Problem is that I don't know how to execute that, so if someone can help me out on this one that would be great! Also if there's a better idea I'm definitely open for it.

  • 2
    Its not clear to me exactly what you want. Is the shell script passed the filename? Does it move files? Does it just echo a new filename based on one from the environment variables you mentioned? – Brian Oct 12 '15 at 23:54
  • Ah, my bad. What I meant was I want to be able to change the artifact filename + change the version tag in the pom file. – Fadi Oct 13 '15 at 13:53
  • My guess is that the easiest way is to increment the number and write to a temp file in the workspace then everytime the build is run it fetches that number and inputs it in the the filename + pom file... and so on. – Fadi Oct 13 '15 at 13:55
  • What do you mean with "a shell script that executes on failure"? What is the big picture here? It seems to me you are trying to do things under the hood that jenkins should solve for you. – Bram Oct 13 '15 at 18:54
0

Assuming the workspace is persistent, here's a thing to trigger after each build:

if [ -f counterfile.txt ]; then
  num=$(cat counterfile.txt)
else
  num=0
fi
num=$((num+1))
echo $num>counterfile.txt

filename=$POM_ARTIFACTID-$POM-VERSION.jar
newfilename=echo $filename | sed "s/-SNAPSHOT/-$num-SNAPSHOT/"
mv $filename $newfilename
  • 1
    should "echo num..." be "echo $num..." ? – Jeff Schaller Oct 13 '15 at 18:36
  • Yes it should. Editing. – snetch Oct 13 '15 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.