【问题标题】:How can I get system configuration for jenkins using remote access API如何使用远程访问 API 获取 jenkins 的系统配置
【发布时间】:2017-03-31 14:38:50
【问题描述】:

Jenkins 提供了不错的Remote Access API,可用于获取大量信息,例如作业和视图。

我想知道是否或如何从远程访问 API 获取系统(全局)配置。

这些信息在网页http://your.jenkins.url/manage

【问题讨论】:

标签: api jenkins


【解决方案1】:

您可以通过

获取您的主节点/节点的配置
http://your.jenkins.url/computer/(master)/config.xml

这对你来说足够了吗?

注意:自 2014 年年中起,POSTing has been disabled

要了解有关 API 的更多信息,请尝试将 /api 添加到某些 URL 的末尾。

要查找哪些对象公开了 API,请在 https://github.com/jenkinsci/jenkins/find/master 中搜索 _api.jelly(按“t”,然后输入“_api.jelly”)

【讨论】:

  • 是的,太棒了!你怎么会知道这个? ;-),你能列出你从哪里得到这些信息吗?
  • @LarryCai 发现浏览your.jenkins.url/computer/(master)/api的信息。在如何查找更多 API 信息的答案中添加了更多信息。
  • 太棒了,现在我几乎知道所有的 API
  • 这不再起作用了。看起来像 POST 到 config.xml 已被故意禁用。 github.com/jenkinsci/jenkins/pull/1258
  • 你是对的。 POST 已经有一段时间没有工作了。 GETing 仍然有效。我会更新的。
【解决方案2】:

对于具体的系统配置信息,例如所有环境变量等,不是您的描述所要求的,而是标题,您需要将 /systemInfo 附加到 URL 的末尾。

http:<YourURLHere>/systemInfo

然后您必须对其进行一些身份验证,然后您应该会看到信息的 HTML 列表。所以你必须做一些解析,就像你使用 grep 一样,它只会返回整个表。

http://fakeurl.com/systemInfo --user 'fakeuser':'fakepasswd'

【讨论】:

    【解决方案3】:

    在我的插件中,我访问了系统配置,“Artifactory 凭据”。 1)在 pom.xml 中添加工件依赖项。 即

    <dependency>
                <groupId>org.jenkins-ci.plugins</groupId>
                <artifactId>artifactory</artifactId>
                <version>2.9.0</version>
                <type>jar</type>
            </dependency>
    

    2) 找到准确的 global.jelly 配置。 我在 org.jfrog.hudson.ArtifactoryBuilder 中找到

                                <table style="width: 100%" id="legacyDeployerCredentials${server.url}">
                                    <f:entry title="Username"
                                             help="/plugin/artifactory/help/common/help-deployerUserName.html">
                                        <f:textbox name="username" field="username"
                                                   value="${server.deployerCredentialsConfig.username}"/>
                                    </f:entry>
                                    <f:entry title="Password"
                                             help="/plugin/artifactory/help/common/help-deployerPassword.html">
                                        <f:password name="password" field="password"
                                                    value="${server.deployerCredentialsConfig.password}"/>
                                    </f:entry>
                                </table>
                            </f:block>
                        </f:section>
    

    3) 识别用于应用配置的类。 org.jfrog.hudson.ArtifactoryBuilder.java 4)创建jenkins实例并访问插件描述符获取用户凭据。

    ArtifactoryBuilder.DescriptorImpl ab = (ArtifactoryBuilder.DescriptorImpl) jenkins.model.Jenkins.getInstance().getDescriptor(ArtifactoryBuilder.class);
            ArtifactoryServer server = ab.getArtifactoryServers().iterator().next();
            this.userName =  server.getDeployerCredentialsConfig().getUsername();
            this.password =  server.getDeployerCredentialsConfig().getPassword();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-20
      相关资源
      最近更新 更多