在Jenkins上发布时,为什么我的测试无法看到我的系统属性? [英] Why can't my tests see my system property when I release on Jenkins?

查看:119
本文介绍了在Jenkins上发布时,为什么我的测试无法看到我的系统属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些单元测试代码,打印出名为"JENKINS_BUILD"的System.property的值.当我在本地运行以下命令时,此属性具有值:

I wrote some unit test code that prints out the value of a System.property named "JENKINS_BUILD". This property has a value when I run these command locally:

mvn --batch-mode test -DJENKINS_BUILD=true
mvn test -DargLine="-DJENKINS_BUILD=true"
etc.

但是,无论我做什么,当它们在Jenkins上运行时,都无法将其添加到测试中.这是我在此处使用的命令行选项:

But no matter what I do, I cannot get this property into my tests when they are run on Jenkins. This is the command line option I'm using there:

mvn -DargLine="-DJENKINS_BUILD=true" --batch-mode -Dresume=false release:prepare release:perform

稍有不同,但我不明白为什么会如此.为什么在Jenkins上System.getProperty("JENKINS_BUILD")为null但在我的本地环境中为"true"?这与使用release:prepare release:perform有关吗?

Slightly different, but I don't see why it would matter. Why is System.getProperty("JENKINS_BUILD") null on Jenkins but "true" in my local environment? Does this have something to do with using release:prepare release:perform?

我认为这基本上是相同的问题,但是我没有把握.不同之处在于,他试图将参数传递给release插件,而我试图将参数传递给surefire插件.另外,我想在命令行中定义值,而不必更改我的pom.xml.有办法吗?

I think this is basically the same question, but I'm not sure. The difference is he's trying to pass arguments into the release plugin, I'm trying to pass them into the surefire plugin. Also, I want to define the value in the command line without having to change my pom.xml. Is there a way to do that?

FWIW ,我链接到的解决方案确实有效.

推荐答案

请注意,如果您不分叉JVM,则会找到在maven命令行上设置的属性;否则,将显示错误.但是,如果您确实分叉了JVM,则需要将属性复制到分叉的JVM的清单列表中.

Note that if you do not fork your JVM, the properties you set on the maven command line are found; but, if you do fork your JVM the properties need to be copied on the forked JVM's argment list.

我猜测您正在分叉构建的某些方面,但未传递新的argline,或者传递的新argline不能从启动(设置)属性中复制必要的值.

I am guessing that you are forking some aspect of your build, but not passing in a new argline, or are passing in a new argline that doesn't copy the necessary value from the launched (set) property.

这可能意味着在设置了参数和未设置参数的两种情况下,都可能需要设置默认(空)属性以使argline配置正确.这就是链接中第二个示例"(Sander Verhagen的示例)所详述的内容,即使并不清楚原因.

This might mean that you could need to set a default (empty) property to make your argline configuration correct in both cases where the argument is set and where the argument is not set. That's what the second "example" in your link (Sander Verhagen's example) is detailing, even if it isn't explicit as to why.

关于为什么在maven-release-plugin中经常遇到这种情况,请记住,在maven-release-plugin中,您有一个父" maven进程来驱动两个完整的嵌套Maven构建.无法将参数传递给子代版本将意味着子代运行时没有必需的参数(因为它们仅是父活动的参数,而不是两个maven运行来构建发行版和下一个快照版本.

As far as why this is often encountered in the maven-release-plugin, keep in mind that during the maven-release-plugin you have one "parent" maven process driving two complete nested maven builds. Failure to pass arguments to the children builds will mean the children run without the required arguments (as they are only argument to the parent activity, not the two maven runs to build the release version and the next snapshot version.

这篇关于在Jenkins上发布时,为什么我的测试无法看到我的系统属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆