简体   繁体   中英

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!

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.

如果你的意思是你只想直接传递* ,只需使用单引号来避免shell应用globbing:

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

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

Documentation states

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

and if you would deploy extra 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 extra files to deploy explicitly by using additional files , types , classifies parameters, ex.:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM