0

I run a shell script (Centos 6.7) from jenkins containing this command, in order import root environment:

 env -i `cat /home/admin/root_environment.sh` /home/admin/create_user.sh

The root_environment was generated with

 env > root_environment.sh

the script create_user.sh contains

/usr/sbin/useradd -p "pass" "username"

Jenkins is running with its own jenkins user. The script create_user.sh is working correctly if I run it as root, however, running from jenkins I get:

 useradd: cannot lock /etc/passwd; try again later
0

You could add user jenkins to the wheel group with sudo privileges (as root)

usermod -aG wheel jenkins

and then use this in your script

echo "jenkins-password" | sudo -S /usr/sbin/useradd -p "pass" "username"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.