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
Glasnhost
  • 541
  • 3
  • 10
  • 19

1 Answers1

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"
Freddy
  • 1,999
  • 5
  • 12