Automatically setup jenkins users with CLI

Arnaud picture Arnaud · Apr 8, 2012 · Viewed 14.7k times · Source

I did not find any reference to user related commands for the jenkins-cli tool.

I need this to automate deployment.

Any comeback?

Answer

Abhijit picture Abhijit · Oct 5, 2015

To use jenkins internal database simply use the following command.

echo 'jenkins.model.Jenkins.instance.securityRealm.createAccount("user1", "password123")' | \
   java -jar jenkins-cli.jar -s http://localhost:8080/ groovy =

This will create user=user1 with password=password123


If you have any existing user and have restricted anonymous access to your jenkins, you can specify the username and password with

--username "user_name" and --password "password"