How to get users and their permissions from Jenkins through APIs?

I am working on a project where I have to grab all the details of a user which I see on mange roles page for an organization including their permission assignments. I think their is no CLI or any script that give us this information. Any help from the community or Jenkins dev team will be appreciated.

Thanks in Advance.

Hello @ianIt and welcome to this community :wave:

I think you could use the Jenkins API to programmatically fetch this information.
For example, I ran a simple GET /asynchPeople/api/xml?depth=1 on my instance and got:

<?xml version="1.0"?>
<people _class="hudson.model.View$AsynchPeople$People">
  <user>
    <lastChange>1686672521844</lastChange>
    <project _class="org.jenkinsci.plugins.workflow.job.WorkflowJob">
      <name>stf</name>
      <url>http://localhost:8080/job/MultiBranchAndroidPipeline/job/stf/</url>
      <color>red</color>
    </project>
    <user>
      <absoluteUrl>http://localhost:8080/user/noreply</absoluteUrl>
      <fullName>noreply</fullName>
    </user>
  </user>
  <user>
    <lastChange>1685967040220</lastChange>
    <project _class="org.jenkinsci.plugins.workflow.job.WorkflowJob">
      <name>main</name>
      <url>http://localhost:8080/job/AutoUpdaterMultiBranches/job/main/</url>
      <color>blue</color>
    </project>
    <user>
      <absoluteUrl>http://localhost:8080/user/gounthar</absoluteUrl>
      <fullName>gounthar</fullName>
    </user>
  </user>
  <user>
    <user>
      <absoluteUrl>http://localhost:8080/user/admin</absoluteUrl>
      <fullName>admin</fullName>
    </user>
  </user>
  <user>
    <user>
      <absoluteUrl>http://localhost:8080/user/116569+gounthar</absoluteUrl>
      <fullName>116569+gounthar</fullName>
    </user>
  </user>
  <user>
    <user>
      <absoluteUrl>http://localhost:8080/user/system</absoluteUrl>
      <fullName>SYSTEM</fullName>
    </user>
  </user>
  <user>
    <user>
      <absoluteUrl>http://localhost:8080/user/49699333+dependabot%5Bbot%5D</absoluteUrl>
      <fullName>49699333+dependabot[bot]</fullName>
    </user>
  </user>
  <user>
    <user>
      <absoluteUrl>http://localhost:8080/user/109359706+myjenkinsinstancev%5Bbot%5D</absoluteUrl>
      <fullName>109359706+myjenkinsinstancev[bot]</fullName>
    </user>
  </user>
</people>

As you say Manage Roles I assume you’re using Role-based Authorization Strategy
It has a REST API that you can query for details.
See https://javadoc.jenkins.io/plugin/role-strategy/com/michelin/cio/hudson/plugins/rolestrategy/RoleBasedAuthorizationStrategy.html#doGetAllRoles(java.lang.String) and
https://javadoc.jenkins.io/plugin/role-strategy/com/michelin/cio/hudson/plugins/rolestrategy/RoleBasedAuthorizationStrategy.html#doGetRole(java.lang.String,java.lang.String)

1 Like

Thanks @poddingue but that gives us only the username I want the assigned permissions also which I have done through role-based strategy. Does this API support Pagination or it returns only 100 just like other Jenkins APIs. Is their any way we can get user SID also through API.

1 Like

Thanks @mawinter69 that was very helpful but I have one question whether this API support pagination or it simply returns all data at once

It returns all data at once.