0

why would Jenkins get a different result from shell scripts(redhat 7) alone? I have shell scripts that run fine if I execute them from a terminal, however when I run the scripts from Jenkins they get different results Jenkins 2.263.4

2
  • What kind of different result? Because in your terminal for starters you normally and by default would have a different and richer environment which in Jenkins you would need to explicitly configure – Bob Mar 5 at 17:42
  • Compare which environment variables are set. The PATH could be radically different, for instance. – chicks Mar 5 at 18:32
1

There are a lot of reasons that could happen, but the most common is because of Jenkins not using a "login shell" by default whereas your default local shell is a login shell. This means that it sources your .profile, .bash_profile, or other login scripts are executed locally, but not when launching remotely.

There's a few different ways to make a login shell, but if you were using bash try this at the top of your script:

#!/bin/bash -l

Alternatively, if you're missing an environment variable that would cause different behavior as well. Run printenv on your local shell, then run that as part of a Jenkins shell command, and compare to see if there's a variable that isn't getting defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.