Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - Execute shell commands with wildcards

I am trying to get Jenkins to execute a shell command but still allow wildcards to be used. Here's what I'm trying to do for reference:

mvn deploy:deploy-file -Dpackaging=jar -DrepositoryId=snapshots -Durl=http://nexus.example.net/content/repositories/snapshots -DpomFile=Spigot/Spigot-Server/pom.xml -Dfile=Spigot/Spigot-Server/target/spigot-*.jar

I need to be able to deploy this jar through the above command because the git repository for that project isn't owned or operated by me, so I need to be able to deploy it directly to my own Nexus instance. In order to ensure that it will support all possible versions of the compiled jar, I must use a wild card. Unfortunately, when Jenkins tries to execute the command, it takes the wildcard literally. I'm really not sure how to solve this, I would appreciate any help you can provide. Thank you!

like image 289
mattrick Avatar asked Oct 19 '22 11:10

mattrick


2 Answers

If it's a simple single .jar file try this:

mvn deploy:deploy-file -Dpackaging=jar -DrepositoryId=snapshots -Durl=http://nexus.example.net/content/repositories/snapshots -DpomFile=Spigot/Spigot-Server/pom.xml -Dfile=$(find Spigot/Spigot-Server/target/ -name 'spigot-*.jar')

If it's multiple files, it's a bit more complicated:

The maven deploy-file parameters files, classifiers and types are used when you want to deploy multiple artifacts under the same (groupId, artifactId, version) - for example a .jar and -sources.jar

Even for that use case, the syntax is somewhat counterintuitive - you must use file=file1.jar for the first artifact, and then files=file1-sources.jar,file1-test-sources.zip,.. for the rest, while using classifier/classifiers (and packaging/types) in the same way (positional) to specify classifier/type of each artifact you are uploading.

If your use case is uploading artifacts of different versions, you will need to do one maven deploy-file call for each version.

You also might consider some alternatives:

  1. (depending on how many artifacts, and how often new ones will come) - upload these artifacts manually to Nexus

  2. Make you Nexus proxy another Nexus repository that serves these artifacts.

like image 168
Borut Hadžialić Avatar answered Nov 15 '22 05:11

Borut Hadžialić


If you mean you just want the * to be passed on directly, just use single quotes to avoid the shell from applying globbing:

mvn deploy:deploy-file [...] '-Dfile=Spigot/Spigot-Server/target/spigot-*.jar'
like image 44
Jon Skeet Avatar answered Nov 15 '22 05:11

Jon Skeet