Pass env variables to junit test from jenkins

1,413 views
Skip to first unread message

Serega Sheypak

unread,
Nov 23, 2012, 2:09:14 PM11/23/12
to jenkins...@googlegroups.com
Hi, I have pretty silly question. Please help me.
I do have a test which gets parameters from env variables:

public Conf(){
        this.hostname = System.getProperty(WEBAPP_HOST);
        this.port =   System.getProperty(WEBAPP_PORT);
        this.contextPath = System.getProperty(WEBAPP_CONTEXTPATH);
        this.scoringServletname = System.getProperty(WEBAPP_SCORING_SERVLETNAME);

    }
I do pass these variables in this way:
mvn test -DargLine="-Dwebapp.port=12345 -Dwebapp.host=xxx.yyy.net -Dwebapp.contextpath=my-webapp -Dwebapp.my.servletname=myServlet"

How can I do the same using jenkins?
I've tried a lot of stuff, but nothing helps. Conf ogject gets null values during instantiation.

Harpreet singh Wadhwa

unread,
Nov 24, 2012, 1:18:59 AM11/24/12
to jenkins...@googlegroups.com
Are you not using Maven Plugin (Maven type Job)?
As that has a textbox for arguments.

If you are using the maven job and still getting issue, then would need more info on how are you trying to pass these argument, as it should be simple enough, even if you run it from Bash shell / as Bach command (from Jenkins job)

Thanks

Serega Sheypak

unread,
Nov 24, 2012, 2:09:03 AM11/24/12
to jenkins...@googlegroups.com
I've tried different options:
1. jenkins->my project-> configuration ->Pre Steps->execute shell:
export myvar=val1
export myvar=val2
e.t.c.

And I got failed build:
Warning : There are multiple branch changesets here
[mr-url-rating] $ /bin/sh -xe /tmp/hudson7013605956859189867.sh
+ export myvar=val1
/tmp/hudson7013605956859189867.sh: line 2: export: `myvar=val1': not a valid identifier
Build step 'Execute shell' marked build as failure Finished: FAILURE

Then I've tried to set variables using  Environment Injector Plugin
Nothing helps, they are still NULL inside my Java test execution

I've tried to use 
MAVEN_OPTS:
-Dmyvar=val1 -Dmyvar2=val2

And it didn't help also.
What can I try next?

суббота, 24 ноября 2012 г., 10:19:24 UTC+4 пользователь Harpreet singh Wadhwa написал:

Clemens

unread,
Nov 26, 2012, 5:43:08 AM11/26/12
to jenkins...@googlegroups.com
Hey,

have you tried to split it, like this:
variable=value
export variable

So, you are not assigning your variable in your export line.
But, not sure about it.
Greetings


Serega Sheypak

unread,
Nov 26, 2012, 4:58:46 PM11/26/12
to jenkins...@googlegroups.com
I did it here:
Project configuration -> Maven -> Build -> 
Goals and options (input field), the I've added  -DargLine="-Dmyprop=myvalue... etc..."

Thanks, problem is solved.
2012/11/26 Clemens <clemens...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages