【发布时间】:2017-03-31 14:38:50
【问题描述】:
Jenkins 提供了不错的Remote Access API,可用于获取大量信息,例如作业和视图。
我想知道是否或如何从远程访问 API 获取系统(全局)配置。
【问题讨论】:
Jenkins 提供了不错的Remote Access API,可用于获取大量信息,例如作业和视图。
我想知道是否或如何从远程访问 API 获取系统(全局)配置。
【问题讨论】:
您可以通过
获取您的主节点/节点的配置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”)
【讨论】:
对于具体的系统配置信息,例如所有环境变量等,不是您的描述所要求的,而是标题,您需要将 /systemInfo 附加到 URL 的末尾。
http:<YourURLHere>/systemInfo
然后您必须对其进行一些身份验证,然后您应该会看到信息的 HTML 列表。所以你必须做一些解析,就像你使用 grep 一样,它只会返回整个表。
http://fakeurl.com/systemInfo --user 'fakeuser':'fakepasswd'
【讨论】:
在我的插件中,我访问了系统配置,“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();
【讨论】: