Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions jenkins-client-it-docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,7 @@
</plugin>
</plugins>
</build>
<properties>
<docker.container.network>http://127.0.0.1:8080</docker.container.network>
</properties>
<profiles>
<profile>
<activation>
<property>
<name>env.TRAVIS</name>
</property>
</activation>
<properties>
<docker.container.network>http://127.0.0.1:8080/</docker.container.network>
</properties>
</profile>
<profile>
<id>run-docker-its</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ public final class Constant {

/**
* The URL for the running Jenkins server (currently a Docker image). On
* travis it is localhost (127.0.0.1) on my machine it is different. At the
* moment it is solved by a profile in pom..but could that somehow
* identified by docker itself ?
* travis it is localhost (127.0.0.1).
*/
public static final URI JENKINS_URI = URI.create(System.getProperty("docker.container.network"));
public static final URI JENKINS_URI = URI.create("http://127.0.0.1:8080/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ public Map<String, View> getViews() throws IOException {
* @throws IOException in case of an error.
*/
public Map<String, View> getViews(FolderJob folder) throws IOException {
List<View> views = client.get(toBaseUrl(folder), MainView.class).getViews();
// This is much better than using &depth=2
// http://localhost:8080/api/json?pretty&tree=views[name,url,jobs[name,url]]
List<View> views = client.get(toBaseUrl(folder) + "?tree=views[name,url,jobs[name,url]]", MainView.class).getViews();
return Maps.uniqueIndex(views, new Function<View, String>() {
@Override
public String apply(View view) {

view.setClient(client);
// TODO: Think about the following? Does there exists a
// simpler/more elegant method?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@
*/
public class JenkinsTriggerHelper {

private JenkinsServer server;
private final JenkinsServer server;
private final Long retryInterval;
private static final Long DEFAULT_RETRY_INTERVAL = 200L;

public JenkinsTriggerHelper(JenkinsServer server) {
this.server = server;
this.retryInterval = DEFAULT_RETRY_INTERVAL;
}

public JenkinsTriggerHelper(JenkinsServer server, Long retryInterval) {
this.server = server;
this.retryInterval = retryInterval;
}

/**
Expand Down Expand Up @@ -114,37 +122,26 @@ public BuildWithDetails triggerJobAndWaitUntilFinished(String jobName, boolean c
*/
private BuildWithDetails triggerJobAndWaitUntilFinished(String jobName, QueueReference queueRef)
throws IOException, InterruptedException {
JobWithDetails job;
job = this.server.getJob(jobName);
JobWithDetails job = this.server.getJob(jobName);
QueueItem queueItem = this.server.getQueueItem(queueRef);

while (!queueItem.isCancelled() && job.isInQueue()) {
// TODO: May be we should make this configurable?
Thread.sleep(200);
Thread.sleep(retryInterval);
job = this.server.getJob(jobName);
queueItem = this.server.getQueueItem(queueRef);
}

Build build = server.getBuild(queueItem);
if (queueItem.isCancelled()) {
// TODO: Check if this is ok?
// We will get the details of the last build. NOT of the cancelled
// build, cause there is no information about that available cause
// it does not exist.
BuildWithDetails result = new BuildWithDetails(job.getLastBuild().details());
// TODO: Should we add more information here?
result.setResult(BuildResult.CANCELLED);
return result;
return build.details();
}

job = this.server.getJob(jobName);
Build lastBuild = job.getLastBuild();

boolean isBuilding = lastBuild.details().isBuilding();
boolean isBuilding = build.details().isBuilding();
while (isBuilding) {
// TODO: May be we should make this configurable?
Thread.sleep(200);
isBuilding = lastBuild.details().isBuilding();
Thread.sleep(retryInterval);
isBuilding = build.details().isBuilding();
}

return lastBuild.details();
return build.details();
}
}