I have a scenario where I want to trigger Jenkins Build with parameters remotely.
I am using following jar in my java code to connect to Jenkins:
<dependency>
<groupId>com.cdancy</groupId>
<artifactId>jenkins-rest</artifactId>
<version>0.0.25</version>
<classifier>all</classifier>
</dependency>
Following is the code snippet I use to check Jenkins version.
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());
I get the following error:
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}]
How do I set the SSLContext/certificate with the Jenkins client?
Or should I use any other dependency to connect to Jenkins and build a job with parameters?
Thank you in advance!
To increase the Jenkins API security Cloudbees uses crumb read more on this here https://support.cloudbees.com/hc/en-us/articles/219257077-CSRF-Protection-Explained
Instead of using password try to use an API Token. Open User settings, top right corner --> Configure --> Add new Token Then use the token instead of the password in your java code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.