Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we pass the parameter values from Jenkins job to pom.xml and then to my system property in JAVA code?

My question may look a little easy to answer but I couldn't really work it out.

I am working on a project where I have configured the Jenkins job for my build.

What i have done so far is that I have made a maven job which has the pom.xml path configured and with two goals 'clean test' . When I run it it works just fine.

Now I wanna pass the Paramter value BROWSER from Jenkins which may have value like Firefox, Chrome and i want it to pass to java code so that specific browser may open.

I have used the system property in my code:

protected static final String BROWSER = System.getProperty("BROWSER","chrome");

Now I want to pass the value from jenkins to pom and then java code.

Here is my pom which is faulty:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <systemPropertyVariables>
                        <BROWSER>${env.BROWSER}</BROWSER>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

But here it gives me error like cannot resolve symbol env.BROWSER

WorkAround: As a workaround I have made the command in Jenkins goals look like this:

clean test -DREMOTE_DRIVER=${REMOTE_DRIVER} -DSELENIUM_HOST=${SELENIUM_HOST} -DBROWSER=${BROWSER}

But I think its not the ideal way of doing it.

I have already made the parameters in my Jenkins build Parameter Name - "BROWSER" with choices of 'firefox' 'chrome' and 'ie'.

Now i wana just call it in pom ( i used ${env.BROWSER} ) and then pass to my system property in java code. (It is not working for me)

like image 468
Atishay Avatar asked Dec 05 '25 10:12

Atishay


1 Answers

Environmental properties in jenkins are not the system properties of JVM. To set the properties either you need to set it using commandline. export BROWSER =chrome or you can set it in This build is parameterized section of your jenkins build configuration.

like image 148
Eranda Avatar answered Dec 07 '25 01:12

Eranda