Why does `su` not work in Jenkins?

917 views Asked by At

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.

1

There are 1 answers

0
Etan Reisner On BEST ANSWER

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>.