Automatically setup jenkins users with CLI

社会主义新天地 提交于 2021-02-07 12:27:20

问题


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

I need this to automate deployment.

Any comeback?


回答1:


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.




回答2:


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"




回答3:


If you specify in more detail what you are trying to do people here may help you better. That said, here are some pointers:

All CLI commands are available via http://[jenkins-server]/cli. What's not found there is not available via CLI. You can specify user name / password via --username and --password (or --password-file) options in CLI commands.

Another option for Jenkins automation is to use Python JenkinsAPI.

You can also use tools like wget and curl to perform certain actions (such as starting a build). There you may use user-specific tokens instead of username/password.

Here's another link that can be helpful.



来源:https://stackoverflow.com/questions/10066536/automatically-setup-jenkins-users-with-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!