Search code examples
shelljenkinssu

Why does `su` not work in Jenkins?


su doesn't seem to work as intended when run in Jenkins build job script.

su username1234
whoami 

returns jenkins

My initial guess is that each line of the Jenkins shell script is a new shell. But doing repeated echo $$ on separate lines shows that's not the case.


Solution

  • su doesn't enter an interactive session when in a non-interactive session the way it does in an interactive session.

    In a shell script you get to run a single command in the su context su <user> <command>.