如何通过api获取所有詹金斯用户 [英] how to get all the jenkins users through api

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

问题描述

我正在尝试通过使用api来吸引jenkins中的所有用户.

例如,我在邮递员中命中了以下命令,它向我展示了詹金斯中的所有工作.

网址= 192.168.195.150:8080/api/json?pretty=true

结果:

{

    "_class": "hudson.model.Hudson",

    "assignedLabels": [

        {
            "name": "master"
        }
    ],
    "mode": "NORMAL",
    "nodeDescription": "the master Jenkins node",
    "nodeName": "",
    "numExecutors": 2,
    "description": null,
    "jobs": [
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Apache_kafka_Consumer_Info",
            "url": "http://192.168.192.198:8080/job/Apache_kafka_Consumer_Info/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Apache_Kafka_Zookeeper_Start",
            "url": "http://192.168.192.198:8080/job/Apache_Kafka_Zookeeper_Start/",
            "color": "red"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Apache_Kafka_Zookeeper_Status",
            "url": "http://192.168.192.198:8080/job/Apache_Kafka_Zookeeper_Status/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "AWS_Lambda",
            "url": "http://192.168.192.198:8080/job/AWS_Lambda/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Input_Validation",
            "url": "http://192.168.192.198:8080/job/Input_Validation/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "loginserver-CI",
            "url": "http://192.168.192.198:8080/job/loginserver-CI/",
            "color": "blue"
        },
        {
            "_class": "hudson.maven.MavenModuleSet",
            "name": "loginserver-CI-1",
            "url": "http://192.168.192.198:8080/job/loginserver-CI-1/",
            "color": "blue"
        },
        {
            "_class": "hudson.maven.MavenModuleSet",
            "name": "loginserver-CI-2",
            "url": "http://192.168.192.198:8080/job/loginserver-CI-2/",
            "color": "blue"
        },
        {
            "_class": "hudson.maven.MavenModuleSet",
            "name": "loginserver-CI-3",
            "url": "http://192.168.192.198:8080/job/loginserver-CI-3/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "M_test",
            "url": "http://192.168.192.198:8080/job/M_test/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "parameter",
            "url": "http://192.168.192.198:8080/job/parameter/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Remote_Deploy",
            "url": "http://192.168.192.198:8080/job/Remote_Deploy/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Remote_Deploy_1",
            "url": "http://192.168.192.198:8080/job/Remote_Deploy_1/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Tomcat_Status",
            "url": "http://192.168.192.198:8080/job/Tomcat_Status/",
            "color": "yellow"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Version_Check",
            "url": "http://192.168.192.198:8080/job/Version_Check/",
            "color": "blue"
        }
    ],
    "overallLoad": {},
    "primaryView": {
        "_class": "hudson.model.AllView",
        "name": "all",
        "url": "http://192.168.192.198:8080/"
    },
    "quietingDown": false,
    "slaveAgentPort": -1,
    "unlabeledLoad": {
        "_class": "jenkins.model.UnlabeledLoadStatistics"
    },
    "useCrumbs": true,
    "useSecurity": true,
    "views": [
        {
            "_class": "hudson.model.AllView",
            "name": "all",
            "url": "http://192.168.192.198:8080/"
        }
    ]
}

如何修改该网址,以便列出Jenkins中的所有用户?

如果列出用户权限以及分配给每个用户的作业,那就更好了.

解决方案

您可以使用以下方法获取用户列表:-

https://<yourjenkins>/asynchPeople/api/xml?depth=1

使用jenkinsfile中的以下代码获取所有Jenkins用户:-

import hudson.model.User

User.getAll().each { user ->
   println user
}

有关更多信息,请参考链接:

I'm trying to get all the user in jenkins by using api .

For example I hit the following command in postman and it is showing me all the jobs in jenkins .

Url = 192.168.195.150:8080/api/json?pretty=true

Result:

{

    "_class": "hudson.model.Hudson",

    "assignedLabels": [

        {
            "name": "master"
        }
    ],
    "mode": "NORMAL",
    "nodeDescription": "the master Jenkins node",
    "nodeName": "",
    "numExecutors": 2,
    "description": null,
    "jobs": [
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Apache_kafka_Consumer_Info",
            "url": "http://192.168.192.198:8080/job/Apache_kafka_Consumer_Info/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Apache_Kafka_Zookeeper_Start",
            "url": "http://192.168.192.198:8080/job/Apache_Kafka_Zookeeper_Start/",
            "color": "red"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Apache_Kafka_Zookeeper_Status",
            "url": "http://192.168.192.198:8080/job/Apache_Kafka_Zookeeper_Status/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "AWS_Lambda",
            "url": "http://192.168.192.198:8080/job/AWS_Lambda/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Input_Validation",
            "url": "http://192.168.192.198:8080/job/Input_Validation/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "loginserver-CI",
            "url": "http://192.168.192.198:8080/job/loginserver-CI/",
            "color": "blue"
        },
        {
            "_class": "hudson.maven.MavenModuleSet",
            "name": "loginserver-CI-1",
            "url": "http://192.168.192.198:8080/job/loginserver-CI-1/",
            "color": "blue"
        },
        {
            "_class": "hudson.maven.MavenModuleSet",
            "name": "loginserver-CI-2",
            "url": "http://192.168.192.198:8080/job/loginserver-CI-2/",
            "color": "blue"
        },
        {
            "_class": "hudson.maven.MavenModuleSet",
            "name": "loginserver-CI-3",
            "url": "http://192.168.192.198:8080/job/loginserver-CI-3/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "M_test",
            "url": "http://192.168.192.198:8080/job/M_test/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "parameter",
            "url": "http://192.168.192.198:8080/job/parameter/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Remote_Deploy",
            "url": "http://192.168.192.198:8080/job/Remote_Deploy/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Remote_Deploy_1",
            "url": "http://192.168.192.198:8080/job/Remote_Deploy_1/",
            "color": "blue"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Tomcat_Status",
            "url": "http://192.168.192.198:8080/job/Tomcat_Status/",
            "color": "yellow"
        },
        {
            "_class": "hudson.model.FreeStyleProject",
            "name": "Version_Check",
            "url": "http://192.168.192.198:8080/job/Version_Check/",
            "color": "blue"
        }
    ],
    "overallLoad": {},
    "primaryView": {
        "_class": "hudson.model.AllView",
        "name": "all",
        "url": "http://192.168.192.198:8080/"
    },
    "quietingDown": false,
    "slaveAgentPort": -1,
    "unlabeledLoad": {
        "_class": "jenkins.model.UnlabeledLoadStatistics"
    },
    "useCrumbs": true,
    "useSecurity": true,
    "views": [
        {
            "_class": "hudson.model.AllView",
            "name": "all",
            "url": "http://192.168.192.198:8080/"
        }
    ]
}

How can I modify that Url so that I can list out all the users in Jenkins ?

It would be more better if it list out user permissions along with the jobs allocated to each user.

解决方案

You can get the list of Users using below:-

https://<yourjenkins>/asynchPeople/api/xml?depth=1

Get all the Jenkins user using the below code in jenkinsfile:-

import hudson.model.User

User.getAll().each { user ->
   println user
}

Please refer the link for more information:

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

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