Skip to content
Permalink
Browse files

JENKINS-14577 Only set job name/status if it hasnt been already set

  • Loading branch information
rossrowe committed Jul 26, 2012
1 parent 37311c8 commit 74fa15d834dd5b9b02b588de7f4aebde9623516c
@@ -108,7 +108,7 @@
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>saucerest</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.saucelabs</groupId>
@@ -151,13 +151,13 @@
<dependency>
<groupId>com.saucelabs.selenium</groupId>
<artifactId>sauce-ondemand-driver</artifactId>
<version>1.3</version>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.saucelabs.selenium</groupId>
<artifactId>selenium-client-factory</artifactId>
<version>1.3</version>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -236,14 +236,24 @@ private void processBuildOutput(AbstractBuild build) {

String jobName = sessionId[1];
if (StringUtils.isNotBlank(jobName)) {
String json = sauceREST.getJobInfo(id);
JSONObject jsonObject = new JSONObject(json);
Map<String, Object> updates = new HashMap<String, Object>();
//only store passed/name values if they haven't already been set
if (jsonObject.get("passed").equals(JSONObject.NULL)) {
updates.put("passed", build.getResult().equals(Result.SUCCESS));
}
if (jsonObject.get("name").equals(JSONObject.NULL)) {
updates.put("name", jobName);
}
updates.put("public", false);
updates.put("build", build.getNumber());
updates.put("passed", build.getResult().equals(Result.SUCCESS));
sauceREST.updateJobInfo(jobName, updates);
}
} catch (IOException e) {
logger.log(Level.WARNING, "Error while updating job " + id, e);
} catch (JSONException e) {
e.printStackTrace();
}
}

@@ -35,6 +35,8 @@
import hudson.tasks.junit.TestResult;
import hudson.util.Secret;
import org.apache.commons.io.IOUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
@@ -70,14 +72,24 @@ public SauceOnDemandReportFactory getTestData(AbstractBuild<?, ?> build, Launche
for (String[] id : sessionIDs) {
hasResult = true;
try {
String json = sauceREST.getJobInfo(id[0]);
JSONObject jsonObject = new JSONObject(json);
Map<String, Object> updates = new HashMap<String, Object>();
updates.put("name", cr.getFullName());
//only store passed/name values if they haven't already been set
if (jsonObject.get("passed").equals(JSONObject.NULL)) {
updates.put("passed", cr.isPassed());
}
if (jsonObject.get("name").equals(JSONObject.NULL)) {
updates.put("name", cr.getFullName());
}

updates.put("public", false);
updates.put("build", build.getNumber());
updates.put("passed", cr.isPassed());
sauceREST.updateJobInfo(id[0], updates);
} catch (IOException e) {
e.printStackTrace(buildListener.error("Error while updating job " + id));
} catch (JSONException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
if (sessionIDs.isEmpty()) {
@@ -3,6 +3,7 @@
import com.saucelabs.rest.Credential;
import com.saucelabs.sauce_ondemand.driver.SauceOnDemandSelenium;
import com.saucelabs.selenium.client.factory.SeleniumFactory;
import com.thoughtworks.selenium.Selenium;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import org.junit.Assert;
@@ -47,9 +48,11 @@ public String doTest() throws IOException, InterruptedException {

System.setProperty("SELENIUM_DRIVER", new com.saucelabs.ci.Browser("Firefox3_0_Linux", "linux", "firefox", "3.0", "firefox").getUri());

SauceOnDemandSelenium selenium = (SauceOnDemandSelenium) SeleniumFactory.create();
Selenium selenium = SeleniumFactory.create();
selenium.start();
String sessionId = selenium.getSessionId();

SauceOnDemandSelenium sauceOnDemandSelenium = (SauceOnDemandSelenium) selenium;
String sessionId = sauceOnDemandSelenium.getSessionIdValue();


try {

0 comments on commit 74fa15d

Please sign in to comment.
You can’t perform that action at this time.