1

I check the environment variables and can see that they are different for what Jenkins has. I launched the terminal under admin (user name) and executed a simple command id -un; echo $PATH

~ admin$ id -un
admin
~ admin$ echo $PATH
/Users/admin/.rvm/gems/ruby-2.2.3/bin:/Users/admin/.rvm/gems/ruby-2.2.3@global/bin:/Users/admin/.rvm/rubies/ruby-2.2.3/bin:/Users/admin/.rvm/bin:/Users/admin/.gem/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/admin/.gem/bin:/Users/admin/.gem/bin

When I'm running the same command from shell script as part of Jenkins build I can see different output:

+ id -un
admin
+ echo /usr/bin:/bin:/usr/sbin:/sbin
/usr/bin:/bin:/usr/sbin:/sbin

It seems that I have ~/.bach_profile which is ignored by Jenkins or probably it is executed after Jenkins has been loaded.

How can I fix that?

ps: Jenkins is launched under admin user as a daemon.

Alex Sorokoletov
  • 3,102
  • 2
  • 30
  • 52
Mando
  • 11,414
  • 17
  • 86
  • 167

2 Answers2

1

Jenkins is designed to give you absolute control over the environment your build runs in. This lets you test your code under "lab conditions", so that if something breaks, you know exactly what the conditions were.

As part of giving you that "same every time" reliability, it resets all your environment variables, so that the environment your build runs in is independent of the environment Jenkins runs in.

If you want to set an environment variable for your Jenkins build, take a look at How to set environment variables in Jenkins?

Community
  • 1
  • 1
Lucas Wilson-Richter
  • 2,274
  • 1
  • 18
  • 24
  • I'm using EnvInject a lot, but it's just inconvenient to configure them with every build. I have also tried to configured them globally via `Manage Jenkins->Configure System->Environment Variables` but it seems that it doesn't work, environment variables entered there have no affect on my environment variables during a build. The only way I found is the custom plist in `/usr/local/opt/jenkins/...` but it's really inconvenient. Moreover when I'm installing new software I have to know the configuration and mimic it at Jenkins as well. – Mando Feb 05 '16 at 15:49
0

The default init.d script provided by the jenkins rpm will source the file /etc/sysconfig/jenkins if you add your environment stuff into there, it should pick it up as well.

abe
  • 331
  • 1
  • 6