Sudo command is not working from Jenkins Console while executing shell command. It is still showing user as jenkins, Kindly suggest
+ whoami
jenkins
+ hostname
ip-123-23-34-23
+ sudo su - admin
+ whoami
jenkins
Updated:
How can I execute other commands if my user is admin like export and python command. It is saying python command not found, but if I switch shell to Bash, python command will get execute
+ echo /tmp/jenkins4181446190720754051.sh
/tmp/jenkins4181446190720754051.sh
+ bash
+ sudo su - admin -c whoami
admin
+ bash
+ echo /tmp/jenkins4181446190720754051.sh
/tmp/jenkins4181446190720754051.sh
+ whoami
jenkins
+ export ADMIN_HOME=/home/admin
+ python /home/admin/scripts/bin/script.py STG
/tmp/jenkins4181446190720754051.sh: 11: python: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Kindly suggest
Do not use su
in a non-interactive session, as spawning a login shell without any input is pointless. Instead use the command non-interactively.
sudo -u jenkins whoami
sudo su - admin -c 'whoami'