使用通过预构建 shell 命令获得的变量为 Hudson 中的 Maven 构建设置选项
我有一份 Hudson 工作,运行一个 Maven 目标。在执行此 Maven 目标之前,我添加了一个在构建开始之前运行的步骤,它是一个 shell 脚本,用于获取我想要在“目标和选项”字段中使用的版本号。
因此,在我的作业配置中,在构建环境下,我选中了配置 M2 额外构建步骤框,并在构建之前添加了 shell 脚本。该脚本如下所示:
export RELEASE={command to extract release version}
echo $RELEASE
然后在 Build 部分下,我指向我的“root pom”。在目标和选项中,我希望能够执行如下操作:
-Dbuild.release.version=${RELEASE} deploy
其中build.release.version是POM中引用的maven属性。然而,由于 shell 似乎没有使其变量成为全局变量,所以它不起作用。有什么想法吗?
我唯一的方法是安装 Envfile 插件并获取shell脚本将RELEASE属性写到文件中,然后让插件读取文件,但是所有内容的运行顺序可能会导致问题,似乎必须有更简单的方法......有吗?
提前致谢。
I have a Hudson job that runs a maven goal. Before this maven goal is executed I have added a step to run before the build starts, it is a shell script that obtains the version number that I want to use in the 'Goals and options' field.
So in my job configuration, under Build Environment I have checked the Configure M2 Extra Build Steps box and added a shell script before the build. The script looks like this:
export RELEASE={command to extract release version}
echo $RELEASE
And then under the Build section I point to my 'root pom'. In the Goals and options I then want to be able to do something like this:
-Dbuild.release.version=${RELEASE} deploy
Where build.release.version is a maven property referenced in the POM. However since the shell doesn't seem to make its variables global it doesn't work. Any ideas?
The only one I have is to install the Envfile plugin and get the shell script to write out the RELEASE property to a file and then get the plugin to read the file, but the order in which everything is run may cause problems and it seems like there must be simpler way...is there?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近想做同样的事情,但据我所知,不可能将值从预构建 shell 导出到工作环境。如果有一个 Hudson 插件,我已经错过了。
然而,真正有效的是与您建议的设置类似的设置:让预构建 shell 脚本将所需的值写入工作区中的属性文件,然后使用 参数化触发器插件 来触发另一个实际执行工作的作业(在您的情况下,调用 Maven工作)。该插件可以配置为读取它从属性文件传递的参数。因此,第一个作业只有 shell 脚本和构建后触发器,第二个作业则执行实际工作,并具有可用作环境变量的正确参数。
shell 脚本的总体思路:
对于您的目标和选项,类似于:
当然,这并不像人们想要的那么优雅,但对我们来说效果非常好,因为我们的构建一开始就被分成了几个工作,并且我们实际上可以重用第一个触发的其他作业(即使用不同的参数调用它们)。
I recently wanted to do the same, but AFAIK it's not possible to export values from a pre-build shell to the job environment. If there is a Hudson Plugin for this I've missed it.
What did work, however, was a setup similar to what you were suggesting: having the pre-build shell script write the desired value(s) to a property-file in the workspace, and then using the Parametrized Trigger Plugin to trigger another job that actually does the work (in your case, invoke the Maven job). The plugin can be configured to read the parameters it passes from the property file. So the first job has just the shell script and the post-build triggers, and the second one does the actual work, having the correct parameters available as environment variables.
General idea of the shell script:
And for your Goals and options, something like:
Granted, this isn't as elegant as one might want but worked really well for us, since our build was broken into several jobs to begin with, and we can actually reuse the other jobs that the first one triggers (that is, invoke them with different parameters).
当你说它不起作用时,你的意思是你的RELEASE变量没有传递给maven命令吗?我认为问题在于默认情况下,shell 脚本的每一行都是单独执行的,因此环境变量会丢失。
如果您希望整个 shell 脚本像一个脚本文件一样执行,请创建第一行:
我认为这在 shell 脚本构建步骤旁边的帮助信息中进行了描述(如果我错了,那么这是一个好地方寻找正确的语法)。
When you say it doesn't work, do you mean that your RELEASE variable is not passed to the maven command? I believe the problem is that by default, each line of the shell script is executed separately, so environment variables get lost.
If you want the entire shell script to execute as if it was one script file, make the first line:
I think this is described in the Help information alongside the shell script build step (and if I'm wrong, that's a good place to look for the right syntax).