简体   繁体   English

Jenkins - 使用通配符执行shell命令

[英]Jenkins - Execute shell commands with wildcards

I am trying to get Jenkins to execute a shell command but still allow wildcards to be used. 我试图让Jenkins执行shell命令,但仍然允许使用通配符。 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. 我需要能够通过上面的命令部署这个jar,因为该项目的git存储库不是由我拥有或操作的,所以我需要能够将它直接部署到我自己的Nexus实例。 In order to ensure that it will support all possible versions of the compiled jar, I must use a wild card. 为了确保它将支持编译jar的所有可能版本,我必须使用外卡。 Unfortunately, when Jenkins tries to execute the command, it takes the wildcard literally. 不幸的是,当Jenkins尝试执行命令时,它会逐字地采用通配符。 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: 如果它是一个简单的单个.jar文件,请尝试:

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 当您想要在同一个 (groupId,artifactId,version)下部署多个工件时,使用maven deploy-file参数文件分类器类型 - 例如.jar-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. 即使对于那个用例,语法也有些违反直觉 - 你必须使用file = file1.jar作为第一个工件 ,然后使用files = file1-sources.jar,file1-test-sources.zip,.. 其余的 ,同时使用分类器/分类器 (和包装/类型 )以相同的方式(位置)指定要上载的每个工件的分类器/类型。

If your use case is uploading artifacts of different versions , you will need to do one maven deploy-file call for each version . 如果您的用例是上载不同版本的工件 ,则需要为每个版本执行一次maven部署文件调用

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 (取决于有多少工件,以及新工件的频率) - 将这些工件手动上传到Nexus

  2. Make you Nexus proxy another Nexus repository that serves these artifacts. 让Nexus 代理另一个为这些工件提供服务的Nexus存储库

如果你的意思是你只想直接传递* ,只需使用单引号来避免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 . 如果您尝试部署多个文件,我认为问题在于Jenkins或bash命令,而在于使用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.: 因此,如果您指定额外的文件以通过使用其他filestypesclassifies参数,明确部署,将会更好。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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