use of com.offbytwo.jenkins.JenkinsServer in project stashbot by palantir.
the class JenkinsManager method synchronousTriggerBuild.
public void synchronousTriggerBuild(Repository repo, JobType jobType, PullRequest pullRequest) {
try {
String pullRequestId = pullRequest.getId().toString();
String hashToBuild = pullRequest.getToRef().getLatestChangeset();
RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
JobTemplate jt = jtm.getJobTemplate(jobType, rc);
String jenkinsBuildId = jt.getBuildNameFor(repo);
String url = jsc.getUrl();
String user = jsc.getUsername();
String password = jsc.getPassword();
log.info("Triggering jenkins build id " + jenkinsBuildId + " on hash " + hashToBuild + " (" + user + "@" + url + " pw: " + password.replaceAll(".", "*") + ")");
final JenkinsServer js = jenkinsClientManager.getJenkinsServer(jsc, rc);
Map<String, Job> jobMap = js.getJobs();
String key = jt.getBuildNameFor(repo);
if (!jobMap.containsKey(key)) {
throw new RuntimeException("Build doesn't exist: " + key);
}
Builder<String, String> builder = ImmutableMap.builder();
builder.put("repoId", repo.getId().toString());
if (pullRequest != null) {
log.debug("Determined pullRequestId " + pullRequestId);
builder.put("pullRequestId", pullRequestId);
// toRef is always present in the repo
builder.put("buildHead", pullRequest.getToRef().getLatestChangeset().toString());
// fromRef may be in a different repo
builder.put("mergeRef", pullRequest.getFromRef().getId());
builder.put("buildRef", pullRequest.getToRef().getId());
builder.put("mergeRefUrl", sub.buildCloneUrl(pullRequest.getFromRef().getRepository(), jsc));
builder.put("mergeHead", pullRequest.getFromRef().getLatestChangeset().toString());
}
jobMap.get(key).build(builder.build());
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (HttpResponseException e) {
// client
if (e.getStatusCode() == 302) {
// to some URL after the fact.
return;
}
// For other HTTP errors, log it for easier debugging
log.error("HTTP Error (resp code " + Integer.toString(e.getStatusCode()) + ")", e);
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.offbytwo.jenkins.JenkinsServer in project stashbot by palantir.
the class JenkinsManager method synchronousTriggerBuild.
public void synchronousTriggerBuild(Repository repo, JobType jobType, String hashToBuild, String buildRef) {
try {
RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
JobTemplate jt = jtm.getJobTemplate(jobType, rc);
String jenkinsBuildId = jt.getBuildNameFor(repo);
String url = jsc.getUrl();
String user = jsc.getUsername();
String password = jsc.getPassword();
log.info("Triggering jenkins build id " + jenkinsBuildId + " on hash " + hashToBuild + " (" + user + "@" + url + " pw: " + password.replaceAll(".", "*") + ")");
final JenkinsServer js = jenkinsClientManager.getJenkinsServer(jsc, rc);
Map<String, Job> jobMap = js.getJobs();
String key = jt.getBuildNameFor(repo);
if (!jobMap.containsKey(key)) {
throw new RuntimeException("Build doesn't exist: " + key);
}
Builder<String, String> builder = ImmutableMap.builder();
builder.put("buildHead", hashToBuild);
builder.put("repoId", repo.getId().toString());
if (buildRef != null) {
builder.put("buildRef", buildRef);
}
jobMap.get(key).build(builder.build());
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (HttpResponseException e) {
// client
if (e.getStatusCode() == 302) {
// to some URL after the fact.
return;
}
// For other HTTP errors, log it for easier debugging
log.error("HTTP Error (resp code " + Integer.toString(e.getStatusCode()) + ")", e);
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.offbytwo.jenkins.JenkinsServer in project beam by apache.
the class TestService method getUrl.
/**
* Returns the jenkins URL for the last successful build.
*
* @param job Map of runner an job name retrieved from configuration
* @param configuration The input configuration
*
* @return The URL of last successful job.
* @throws URISyntaxException
* @throws IOException
*/
default URL getUrl(Map<String, String> job, Configuration configuration) throws URISyntaxException, IOException {
Map<String, Job> jobs = new JenkinsServer(new URI(configuration.getServer())).getJobs();
JobWithDetails jobWithDetails = jobs.get(job.get(job.keySet().toArray()[0])).details();
return new URL(jobWithDetails.getLastSuccessfulBuild().getUrl() + configuration.getJsonapi());
}
Aggregations