Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically setup jenkins users with CLI

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

I need this to automate deployment.

Any comeback?

like image 686
Arnaud Avatar asked Apr 08 '12 21:04

Arnaud


2 Answers

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"

like image 64
Abhijit Avatar answered Oct 22 '22 08:10

Abhijit


Maybe you don't want to use Jenkins' internal user database at all. There are a host of "Authentication and User Management" plugins.

If you like MySQL, there is a MySQL authenticator (it reads a table of users and passwords), and your "adduser" command could do an insert on that table.

If you like flat files, there is a "Script Security Realm", where you can authenticate with an arbitrary script. Write a file with user and password combos in your favorite format, write an "adduser" script that writes to it, and write an auth script that reads the file and determines whether to authenticate the user.

You can also hook up to an LDAP server, Active Directory, Atlassian Crowd, Unix user accounts (pw_auth), or whatever authentication your application server uses (if it's running off of a Tomcat server, for instance, you can tell Jenkins to let Tomcat authenticate users, and set up Tomcat to do it however you want.

like image 34
Robert Mandeville Avatar answered Oct 22 '22 09:10

Robert Mandeville