jenkins rest-连接到远程jenkins客户端

6tdlim6h  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(450)

我有一个场景,我想用参数远程触发jenkins构建。
我在java代码中使用以下jar连接到jenkins:

<dependency>
   <groupId>com.cdancy</groupId>
   <artifactId>jenkins-rest</artifactId>
   <version>0.0.25</version>
   <classifier>all</classifier>
</dependency>

下面是我用来检查jenkins版本的代码片段。

JenkinsClient client = JenkinsClient.builder()
// Note - I tried endpoint as https://(//my IP goes here):(//my port goes here) without /jenkins suffix. It didnt work also
.endPoint("https://(//my IP goes here):(//my port goes here)/jenkins").
credentials("username:password").build();

SystemInfo systemInfo = client.api().systemApi().systemInfo();
System.out.println(systemInfo.jenkinsVersion());

我得到以下错误:

SystemInfo{errors=[Error{context=null, message=Unexpected exception being thrown: error=Error{context=null, message=PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target connecting to GET host name goes here/crumbIssuer/api/xml?xpath=concat%28//crumbRequestField,%22%3A%22,//crumb%29 HTTP/1.1, exceptionName=com.cdancy.jenkins.rest.shaded.org.jclouds.http.HttpResponseException} connecting to HEAD HTTP/1.1, exceptionName=com.cdancy.jenkins.rest.shaded.org.jclouds.http.HttpResponseException}]

如何在jenkins客户机上设置sslcontext/证书?
或者我应该使用任何其他依赖项来连接到jenkins并使用参数构建作业?
提前谢谢!

k2arahey

k2arahey1#

为了提高jenkinsapi的安全性,cloudbees使用crumb在这里阅读更多https://support.cloudbees.com/hc/en-us/articles/219257077-csrf-protection-explained
尝试使用api令牌而不是使用密码。打开用户设置,右上角-->配置-->添加新令牌,然后在java代码中使用令牌而不是密码

相关问题