2

I'm using Amazon Linux. I have created a jboss user, and after logging in as that user, I can see their $PATH as such

[myuser@mymachine ~]$ sudo su - jboss
[sudo] password for myuser:
Last login: Sun Nov  5 18:19:43 UTC 2017 on pts/0
...
[jboss@mymachine ~]$ which firefox
/usr/local/bin/firefox
[jboss@myuser ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/maven/bin:/usr/java/latest/bin:/home/jboss/.local/bin:/home/jboss/bin

Notice that "firefox" is on my path. I have a Jenkins WAR file running under the user jboss and I have a script (post build step) within my Jenkins job. However, when running that script, the $PATH in Jenkins does not seem to match the jboss user ...

+ whoami
jboss
+ which firefox
which: no firefox in (/usr/local/maven/bin:/usr/java/latest/bin:/usr/java/latest/bin:/sbin:/usr/sbin:/bin:/usr/bin)

How do I get the $PATH when running Jenkins under the jboss user to match the $PATH when logged in as jboss on the terminal?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dave
  • 15,639
  • 133
  • 442
  • 830

2 Answers2

1

You didn't really say, so I am going to assume that your are running Jenkins under the jboss user, otherwise, you can't really expect the environments to match.

The environment that loads is different for an interactive session vs. a non-interactive session. Rather than try to explain it all, a quick google found this page, which seems to explain what is going on.

When Jenkins is running the job, it is probably spawning a non-interactive or non-login shell, resulting in the different environment. It makes sense (generally speaking) that firefox would only be required in a login shell. But if you need to change that, you can find which of the files mentioned in the linked article is adding firefox to the path and you can source that file in youe script (source /path/to/.profile_file)

Optionally, if you are running Jenkins as a different user, or just another way is to modify the PATH when you start your job, and add the paths you know you need to the environment.

Rob Hales
  • 5,123
  • 1
  • 21
  • 33
  • By running "whoami" in my Jenkins shell, I'm revealing who the user is, no? Anyway, I read the link you referenced but it is a generic discussion about the different home scripts taht get run in ashell but makes no mention of how to get Jenkins to inherit its PATH from teh JBoss user under which its running. – Dave Nov 05 '17 at 20:12
  • Ah. right. Missed that. Just find the file in your user's home directory that is adding firefox to the path. That one is not getting sourced for the non-login shell, it seems. Only for an interactive shell. Just source that file in your jenkins job and it should fix the path. – Rob Hales Nov 05 '17 at 20:32
  • Or, move the lines that add firefox to your path to one of the files that IS sourced for a non-login shell. – Rob Hales Nov 05 '17 at 20:33
  • The file whre that is sourced is /etc/profile, as I understand it, invoked by all users. So I'm still at a loss for how to get Jenkins to load that or what files Jenkins is loading at all. – Dave Nov 06 '17 at 03:14
  • `/etc/profile` is typically only executed for interactive shells. Jenkins doesn't run an interactive shell, so that would explain why you don't get the settings. You have 3 choices: Source the /etc/profile (`source /etc/profile`), put the settings from /etc/profile that you want into a file that executes for a non-interactive shell (i.e. /etc/bashrc), or just set the settings directly in your pipeline. – Rob Hales Nov 08 '17 at 05:28
0

This issue due to the firefox not installed in globally. I had the same issue with Jenkins user and Ubuntu user. In ubuntu user I installed npm and I tried to fetch npm in jenkins even I got the same error. Always try to install packages or software globally in case you are going to use the same package for other users.

Jishnunand P K
  • 145
  • 1
  • 8
  • Thanks but I'm not understanding how to fix the problem. How do I configure Jenkins to read the same $PATH from whcih the user under whcih its running is configured? – Dave Nov 05 '17 at 19:48