在通过API詹金斯创建用户 [英] Creating user in jenkins via api

查看:203
本文介绍了在通过API詹金斯创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果我可以用它的API,我可以创造就业机会,创造詹金斯一个新用户,但对于詹金斯的API文档不具有与用户创造任何东西。

I was wondering if I can create a new user in jenkins using its api , I can create jobs , but the api docs for jenkins doesn't have anything related to user creation.

其实我要创建一个新用户之后为用户创建一个新的工作,这一切使用的API。

Actually i have to create a new user followed by creating a new job for that user ,all of this using an api.

谢谢
Shubham

Thanks Shubham

推荐答案

Shubham,

你说的没错,有一个添加一个用户没有明确的CLI命令。但你可以使用这个Groovy脚本(使用CLI执行)。

you're right, there is no explicit CLI command for adding a user. But you could use groovy script for this (using the CLI for execution).

细节取决于你的詹金斯的配置方式。
例如,如果你的詹金斯使用自己的用户数据库,那么你可以通过下面的CLI调用添加一个新用户:

The details depend on how your Jenkins is configured. For example, if your Jenkins uses its own user database, then you could add a new user by the following CLI call:

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

这个shell命令将创建登录user1和密码password123的新用户。
这里的回声送至一个詹金斯CLI线常规code的(注意, = 表示CLI应得到标准输入code)。

This shell command will create a new user with login "user1" and password "password123". Here echo feeds a line of groovy code to a Jenkins CLI (note that = means that CLI should receive code from STDIN).

此外Groovy脚本可以管理用户权限,但是,确切的$ C $,c取决于使用什么授权策略。你可以使用<一个href=\"https://wiki.jenkins-ci.org/display/JENKINS/Grant+Cancel+Permission+for+user+and+group+that+have+Build+permission\"相对=nofollow>此示例脚本的作为一个开始。

Also groovy script allows to manage user permissions, however, the exact code depends on what authorization strategy is used. You could use this sample script as a start.

问候,
尼克

这篇关于在通过API詹金斯创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆