0

I have added a new parameter say cversion -> "xxx" in eclipse Run Configuration.

Now in the testng testcase i try to fetch the value using System.getProperty(). This returns the value correctly "xxx".

P.S : I have maven-surefire plugin added in my pom.xml BUT didn't add the systempropertyvariable.

Now if i try to run the test in Jenkins, the systemproperty variable does NOT return the expected value.It is empty.

Could anyone explain the reason behind this behaviour ?

Manasa
  • 72
  • 10

1 Answers1

1

You can pass as System Property to the Maven Runner by using -D.

mvn -DpropertyName=propertyValue

A similar question was asked and answered here: https://stackoverflow.com/a/34716689/3266467

Sebastian
  • 858
  • 7
  • 21
  • Solution to this issue is to add the systempropertyvariable to the maven-surefire plugin then it works in Jenkins. But my question is why is it defined in this manner, what is the reason behind it.For this, i could not find it documentation so looking out for clarification here. – Manasa Jul 12 '18 at 10:57
  • Sorry, I could not follow which topic need clarification. The `systempropertyvariable` part or the `mvn -D...` command? – Sebastian Jul 12 '18 at 11:07
  • Why is it mandatory to add the SystemProperty variable under maven-surefire plugin in order to have a successful build on Jenkins ? – Manasa Jul 12 '18 at 11:26
  • My best guess would be that the plugin developers needed a way to know where properties are originating since there are two ways of passing properties to the plugin: https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html – Sebastian Jul 12 '18 at 11:30
  • Thank you for your patience.I'm new to Maven development so asking this.okay, i can understand the point you have mentioned above.But, if i do not mention the systemproperty in the plugin and run the test in eclipse (using embedded maven), how does it recognise the property and print the expected value ? – Manasa Jul 12 '18 at 11:57
  • Again I can only guess, but you mentioned that you added the property to the Run Configuration and read it by calling `System.getProperty()` in your test case. Maven seems to need some more convincing to work with the system properties. – Sebastian Jul 12 '18 at 12:05