how to set PATH in Build Wrapper and make use of it in Build

15 views
Skip to first unread message

Nikhil Bhoski

unread,
Feb 20, 2020, 12:14:40 AM2/20/20
to Jenkins Developers
Hi,

My Jenkins plugin has one build Wrapper and one builder class . I want to set the PATH variable in setup() method of BuildWrapper and use it on command line directly in Builder class using ProcessLauncher. I am facing the following issues 

1) I am setting the PATH using context object of BuildWrapper 

 @Override
    public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher launcher,
            TaskListener listener, EnvVars initialEnvironment)
            throws IOException, InterruptedException {
        CommandConstructUtil utils = new CommandConstructUtil(launcher, getLocalMatlab());
        // Set Environment variable

        setEnv(initialEnvironment);
        String nodeSpecificFileSep = utils.getNodeSpecificFileSeperator();

        context.env("mytool", getLocalTool());

        // Add custom tools bin folder to path to access it directly through command line
        context.env("PATH+mytool", getLocalTool() + nodeSpecificFileSep + "bin");
    }


2) In Builder class i am trying to launch it like below 

matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("mytool --runCommands")


With above its not able to launch the tool. However i could do that using cmds("/bash/bin -c mytool --runCommands")

Is there any way that i need not prefix the /bin/bash or cmd.exe and access the tool directly? currently, above approach is not working please help .

Regards 
Nikhil 

Gavin Mogan

unread,
Feb 20, 2020, 12:31:53 AM2/20/20
to jenkin...@googlegroups.com
Have you tried cmds("/usr/bin/printenv") or something to make sure your envs are being set?

the .envs(envVars) is suspicious to me. Does it have all the values you want it to have? What if you just append to PATH directly instead of using the pipeline + syntax?

(I don't know, i'm just throwing out ideas)

Gavin

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/4221dd02-cbec-4315-b0f1-08d793df0412%40googlegroups.com.

Nikhil Bhoski

unread,
Feb 20, 2020, 7:12:50 AM2/20/20
to Jenkins Developers
Yes ,

It shows the path updated in PATH variable however when i launch the process it does not identify the too and it does not invoke it . 

not sure what am i missing here 
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages