4

I have to deploy something using Hudson, so I've created a pom file for maven and the phase I'm having it run is just some bash.

The problem is, I have thing setup in the hudson users bashrc and/or bash_profile that are necessary for stuff to run, but those file don't seem to be sourced when running through hudson/maven. I'd really prefer to keep it running this way rather than use hardcoded stuff and absolute file paths.

I've read online that whatever is referenced in BASH_ENV is sourced for a non-interactive, non-login shell, which is what I'm guessing bash is being run as by maven/hudson.

But, BASH_ENV is empty. And, I can't set it in bashrc or bash_profile because, as I said, those aren't getting sourced, and even /etc/profile doesn't seem to be doing anything.

Is there a way I can set BASH_ENV "permanently", so that (hopefully) it will be sourced when maven runs via hudson and my various paths and such will be as they are when I'm sshing into the machine?

hsiu
  • 271
  • 4
  • 11
  • You may find my answer at http://stackoverflow.com/questions/5836887/ruby-unicorn-and-environment-variables/5985381#5985381 to be some help. Your understanding of bash_profile and BASH_ENV exceed my limited use of bash so that is good. The wrapper script would be my solution. Also, while @PeterLyons makes some valuable points in his 'considered harmful' write up, I think it is a little short details for dealing with software that already exists and relies on env_vars to establish paths, users, cfg options etc. Good luck. – shellter May 19 '11 at 22:21
  • http://stackoverflow.com/questions/6107700/tool-to-extract-java-stack-traces-from-log-files possible duplicate? – Mikhail Krutov Apr 26 '17 at 11:02

1 Answers1

1

You have a few options. The cleanest is probably just to explicitly source the files you depend on from within your hudson bash script. That is self-documenting and clear. Otherwise, you can set BASH_ENV in the script that launches your hudson daemon and it will propagate to child processes. Check out my blog post on why environment variables are considered harmful for my case against using them.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • source doesn't work for me through hudson, I get `/tmp/hudson1788998833539165185.sh: 1: source: not found` I hate environment variables more than anyone, but it's pretty tough for me to get around using PATH and GEM_PATH at the moment. – hsiu May 19 '11 at 22:46
  • 1
    Try doing `echo $SHELL > /tmp/shell.txt` and then make sure hudson is running the shell you think it is (`/bin/sh` vs. `/bin/bash` for example). You're probably running under /bin/sh. See http://stackoverflow.com/questions/2975370/help-with-basic-shell-script-bin-sh-source-not-found/2975393#2975393 for the fact that /bin/sh doesn't have source while bash does. You can fix this by `exec`ing /bin/bash, then source will work. – Peter Lyons May 20 '11 at 04:32
  • `source` is Bash syntax, so will not work if the script is a `/bin/sh` script. Fortunately, the fix is easy: the portable synonym is `.` (just a dot, with a space after it of course). Though if the script uses other Bash features as well, the proper fix is to run it with `/bin/bash` instead. – tripleee Apr 26 '17 at 11:08