Getting $WORKSPACE through java code

446 views
Skip to first unread message

Prakhash Sivakumar

unread,
Jul 14, 2016, 10:30:22 PM7/14/16
to Jenkins Developers
Hi all,

I have modified the zaproxy plugin, in that  I'm passing a file path as $WORKSPACE/DemoProject where zap reports in default get created, I expect this $WORKSPACE needs to get replaced with the actual path like /home/XXX/.jenkins/workspace/ inside the zaproxy plugin, How can I do this ?

Thanks

mnpoonia

unread,
Jul 15, 2016, 2:40:33 AM7/15/16
to Jenkins Developers
You need to read the environment using build.getEnvironment and then write your logic to make change you want. there are chances that $WORKSPACE is not being converted directly(just a guess i havent tried yet). SO you can get the workspace path using build.getRootDir i believe.

Prakhash Sivakumar

unread,
Jul 18, 2016, 3:37:48 AM7/18/16
to Jenkins Developers
Hi mnpoonia,
Thanks for the reply

I was able to retrieve it using AbstractBuild class

AbstractBuild<?, ?> build;
build.getWorkspace().toString();

Thanks

Ido Gadiel

unread,
Jul 18, 2016, 9:28:50 AM7/18/16
to Jenkins Developers
Hi,
you need to check whether your workspace directory is in your slave or in your master:

AbstractBuild r;
hudson.FilePath hudsonFile;
if(r.getWorkspace().isRemote())
{
VirtualChannel vc = r.getWorkspace().getChannel();
String fp = r.getWorkspace().getRemote();
hudsonFile = new hudson.FilePath(vc,fp);
}
else {
hudsonFile = r.getWorkspace();
}

Reply all
Reply to author
Forward
0 new messages