Create or Modify users and permissions by console

Hello everyone,

I am new to Jenkins. I need to add new users and set permissions on about 400 jobs that are in various folders. Can it be done via console using json, yaml or similar?

Thanks in Advance…

1 Like

Hello @lmfp.forums and welcome to this community :wave:

You should be able to add users thanks to JCasc:

jenkins:
  securityRealm:
    local:
      users:
       - id: jenkins-user
         password: password
[...]

As for the jobs, there is the Job DSL plugin, but I haven’t tried it yet. :thinking:

I think @lmfp.forums is talking about giving permissions, not creating users.

It is possible to do through the script console. You’d want loop through all jobs, and then get the … i actually don’t know, one of the properties. @danielbeck might have something, or at least know which property.

Is it the same permission for every job? Why not do it at the top level, or create folders?

add new users

Depends on the security realm. The built-in security realm is usually used for smaller environments, so I don’t think there’s a lot of scriptability built in. While the Script Console allows you access to the Java APIs, probably not what you should do if you’re new to Jenkins. If you still want to try, ideally on a development instance to play around with, HudsonPrivateSecurityRealm (Jenkins core 2.433 API) is probably what you want.

set permissions on about 400 jobs that are in various folders

Depends on the authorization strategy used. When using Matrix Authorization Strategy, each job’s permissions are stored as a job property as part of its configuration.

Each job allows users with Job/Configure permission to read and write the job configuration in its native XML format (config.xml). See the URL /job/JobNameHere/api for some docs. With some XML editing (you may even get away with sed) you can script a round trip of GET / modify / POST for many jobs with some basic shell scripting or similar.