Jenkins - Running Shell Commands Using Wildcards

I am trying to get Jenkins to execute a shell command, but still allow the use of wildcards. Here is what I am 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 deploy this jar using the above command, because the git repository for this project is not owned or managed by me, so I need to be able to deploy it directly to my own Nexus instance. To provide support for all possible versions of the compiled jar, I must use a wild card. Unfortunately, when Jenkins tries to execute a command, he takes the letter literally. I am really not sure how to solve this, I would appreciate any help you can provide. Thanks!

+5
source share
3 answers

If it is a simple .jar file, try the following:

 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 is several files, it is a little more complicated:

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

Even for this case, using the syntax is somewhat inconsistent - you should use file = file1.jar for the first artifact , and then files = file1 -sources.jar, file1-test-sources.zip, .. to relax using the classifier / classifiers (and packaging / types ) in the same way (positional) to indicate the classifier / type of each exhibit that you are loading.

If your use case downloads artifacts of different versions , you will need to do one maven deployment file for each version .

You can also consider some alternatives:

  • (depending on how many artifacts and how often new ones appear) - manually load these artifacts into Nexus

  • Make Nexus Proxy another Nexus repository that services these artifacts.

+2
source

If you mean you just want to pass * directly, just use single quotes to avoid using the globeing shell:

 mvn deploy:deploy-file [...] '-Dfile=Spigot/Spigot-Server/target/spigot-*.jar' 
+1
source

If you are trying to deploy multiple files , I think the problem is not with the Jenkins or bash command, but with the Maven Deploy Plugin .

Documentation Status

 file File - File to be deployed. User property is: file. 

and if you want to deploy additional artifacts, use

 files String - A comma separated list of files for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in types or classifiers, then an error will be raised. User property is: files. 

Thus, it would be better if you specify additional files for deployment explicitly with additional parameters files , types , classifies , for example:

 ... -Dfile=Spigot/Spigot-Server/target/main-spigot.jar \ -Dfiles=$(ls -1d Spigot/Spigot-Server/target/spigot-*.jar | paste -sd ,) -Dtypes=... -Dclassifiers=... 
0
source

Source: https://habr.com/ru/post/1247254/


All Articles