Job restart using API (Perl or Java)
5 answers
Hi all,
Is it possible to restart a failed job using API? How?
TIA
Hi Alex,
I've pasted a sample of some Java code displaying the use of the com.buildforge.services.client.dbo.Build reprepareBuild method. You might also check out this RFE ( http://www.ibm.com/developerworks/support/rational/rfe/execute?use_case=viewChangeRequest&CR_ID=2752 ) if you are looking to select/deselect particular steps on the restart.
import java.util.List;
import com.buildforge.services.client.api.APIClientConnection;
import com.buildforge.services.client.dbo.Build;
import com.buildforge.services.client.dbo.Project;
import com.buildforge.services.common.dbo.BuildDBO.State;
/**
* This class displays sample code for restarting an
* existing build that is in the completed state.
*/
public class ReprepareTest {
private static final String TEST_PROJECT_NAME = "P_2";
private static final int BUILD_TIMEOUT = 90;
private static final String HOST = "localhost";
private static final int PORT = 3966;
private static final String USER = "root";
private static final String PASSWORD = "root";
/**
* Since this is just an example, all of the logic has been
* added to the main method to display a way of using Build's
* reprepare method.
*
* @param args The command line arguments
* @throws Exception Any kind of error that occurs repreparing
*/
public static void main(String[] args) throws Exception {
APIClientConnection conn = new APIClientConnection(HOST, PORT);
conn.authUser(USER, PASSWORD);
Project project = Project.findByName(conn, TEST_PROJECT_NAME);
if (project == null) {
throw new Exception("Could not find project with name: " + TEST_PROJECT_NAME);
}
List<Build> builds = Build.findByProjectUuid(conn, project.getUuid());
if (builds.size() <= 0) {
throw new Exception("Could not find any builds for project: " + TEST_PROJECT_NAME);
}
Build build = builds.get(0);
if (build.getState() != State.COMPLETED) {
throw new Exception("Build '" + build.getTag()
+ "' for project '" + TEST_PROJECT_NAME
+ "' must be in completed state for reprepare.");
}
Build.Request buildRequest = new Build.Request(project);
build = build.reprepareBuild(buildRequest);
build = Build.fireBuild(conn, build.getUuid());
State state = build.getState();
for (int i = 0; ((i < BUILD_TIMEOUT) && (state != State.COMPLETED)); i++) {
Thread.sleep(1000);
build = Build.findByUuid(conn, build.getUuid());
state = build.getState();
}
if (state != State.COMPLETED) {
throw new Exception("Build did not complete in "
+ BUILD_TIMEOUT + " seconds.");
}
}
}
bju
Thanks for a great reply. This seems to work , but with a problem - it skips the step that actually failed. I want to get the same behavior as in the gui - that the failed step is marked by default and is re-run.
Is that possible?
Hi Alex,
I've written a defect to have the API re-run the failed step. If you would like to follow its progress, the link is http://jazz.net/jazz08/web/projects/Rational%20Build%20Forge#action=com.ibm.team.workitem.viewWorkItem&id=17130 .
bju
Thanks for a great reply. This seems to work , but with a problem - it skips the step that actually failed. I want to get the same behavior as in the gui - that the failed step is marked by default and is re-run.
Is that possible?
Hi Alex,
I've written a defect to have the API re-run the failed step. If you would like to follow its progress, the link is http://jazz.net/jazz08/web/projects/Rational%20Build%20Forge#action=com.ibm.team.workitem.viewWorkItem&id=17130 .
bju
Hi,
I am facing a problem , some time my builds are failed by giving a simple error "build forge agent read error" or "timeout" error ,the only solution is just to restart the builds.
but i dont want the manual intervention in the builds.so i wrote a script that fetches the logs and check if there is error like these(error whose solution is just to restart ) the build.
now i want to restart the *SAME BUILD*, but i am not able to do so..
is there any way we can restart the builds exactly as we do in GUI(web interface) through PERL API's.
Thanks for a great reply. This seems to work , but with a problem - it skips the step that actually failed. I want to get the same behavior as in the gui - that the failed step is marked by default and is re-run.
Is that possible?
Hi Alex,
I've written a defect to have the API re-run the failed step. If you would like to follow its progress, the link is http://jazz.net/jazz08/web/projects/Rational%20Build%20Forge#action=com.ibm.team.workitem.viewWorkItem&id=17130 .
bju
Hi,
I am facing a problem , some time my builds are failed by giving a simple error "build forge agent read error" or "timeout" error ,the only solution is just to restart the builds.
but i dont want the manual intervention in the builds.so i wrote a script that fetches the logs and check if there is error like these(error whose solution is just to restart ) the build.
now i want to restart the *SAME BUILD*, but i am not able to do so..
is there any way we can restart the builds exactly as we do in GUI(web interface) through PERL API's.
Hi,
I'll put a post under the other topic at http://jazz.net/forums/viewtopic.php?t=16283 .
Brent Ulbricht
Developer/Lead - RTC Build
Comments
Hello Alex,
I have developed a large number of java and perl api tools for Build Forge. I find it's a great utility when needing to bypass interaction with the Web UI. That being said, your use case seams to be resolved by a Build Forge System setting. Under Administration -> System in the web ui, you will find many tolerance settings for agent timeout and step retries. One in particular might resolve your issue without the need for custom tooling. Step Max Retries, this will retry a step up to the number of times supplied even if the agent timeout failed. There are also other settings to increase the timeout period for the server/agent to be more tolerant to network issues.