SUDO_USER sometimes already set in Jenkins environments
sgoings opened this issue · comments
The change introduced in #221 broke a set of commands I had built that were running in a Jenkins instance. SUDO_USER is injected into the environment thanks to the https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin.
Might I suggest that you prefix SUDO_USER with something rerun specific so that this line doesn't see the Jenkins-injected env var and bail on rerun startup (sudo password prompts and jenkins jobs don't get along too well 😄)
More details on our Jenkins slaves:
- We create an Ubuntu VM which comes along with the admin user: "ubuntu"
- We create a "jenkins" user
- When we start the slave we:
- ssh to the Ubuntu VM, run
sudo su - jenkins
- run a start script which connects the jenkins slave to the jenkins master
- ssh to the Ubuntu VM, run
It's an easy change. I can rename the option from --sudo-user to something else like --sudo-as-user (eg $SUDO_AS_USER) to avoid the conflict. Feel free to suggest a better option name!
I like --sudo-user
for sure... nice and succinct. What about taking a cue from Ansible? http://docs.ansible.com/ansible/become.html
I had also considered --run-as <user>
. I like ansible extra support for method and prompting.
--run-as <user>
works for me.