The second command doesn't run as root

67 views Asked by At

I have created a Jenkins job today, what it does is the Jenkins user should log into another server and run two commands separated by &&:

ssh -i /creds/jenkins [email protected] "sh -c 'sudo su && lxc exec containername bash'"

The logging part works fine, then it runs the sudo su command and becomes root but it never runs the second command.

I even did this manually and from the Jenkins machine logged into the other server (servername). Then ran sh -c "sudo su && lxc exec containername bash" with no luck.

1

There are 1 answers

1
Avihoo Mamka On

Try to execute the second command as a parameter for the sudo su command, like this:

ssh -i /creds/jenkins [email protected] "sh -c 'sudo su -c "lxc exec containername bash"'"