Skip to content
Permalink
Browse files

JENKINS-13794 Expose the Sauce user name and api key as variables

  • Loading branch information
rossrowe committed Jun 9, 2012
1 parent aed1e3e commit a78f7842905cc0a042fb49181d39320602c3e80d
Showing with 50 additions and 15 deletions.
  1. +50 −15 src/main/java/hudson/plugins/sauce_ondemand/SauceOnDemandBuildWrapper.java
@@ -72,6 +72,8 @@
public static final String SELENIUM_HOST = "SELENIUM_HOST";
public static final String SELENIUM_PORT = "SELENIUM_PORT";
public static final String SELENIUM_STARTING_URL = "SELENIUM_STARTING_URL";
private static final String SAUCE_USERNAME = "SAUCE_USER_NAME";
private static final String SAUCE_API_KEY = "SAUCE_API_KEY";

private boolean enableSauceConnect;

@@ -89,6 +91,8 @@
private boolean launchSauceConnectOnSlave = false;
public static final Pattern ENVIRONMENT_VARIABLE_PATTERN = Pattern.compile("[$|%]([a-zA-Z_][a-zA-Z0-9_]+)");



@DataBoundConstructor
public SauceOnDemandBuildWrapper(Credentials
credentials, SeleniumInformation seleniumInformation, String seleniumHost, String seleniumPort, boolean enableSauceConnect, List<String> browsers) {
@@ -149,6 +153,8 @@ public void buildEnvVars(Map<String, String> env) {

env.put(SAUCE_ONDEMAND_BROWSERS, StringEscapeUtils.escapeJava(browsersJSON.toString()));
}
env.put(SAUCE_USERNAME, getUserName());
env.put(SAUCE_API_KEY, getApiKey());
env.put(SELENIUM_HOST, getHostName());
DecimalFormat myFormatter = new DecimalFormat("###");
env.put(SELENIUM_PORT, myFormatter.format(getPort()));
@@ -251,6 +257,48 @@ private File copySauceConnectToSlave(AbstractBuild build, BuildListener listener
return null;
}

public String getUserName() {
if (getCredentials() != null) {
return getCredentials().getUsername();
} else {
PluginImpl p = PluginImpl.get();
if (p.isReuseSauceAuth()) {
com.saucelabs.rest.Credential storedCredentials = null;
try {
storedCredentials = new com.saucelabs.rest.Credential();
return storedCredentials.getUsername();
} catch (IOException e) {
logger.log(Level.WARNING, "Error retrieving credentials", e);
}

} else {
return p.getUsername();

}
}
return "";
}

public String getApiKey() {
if (getCredentials() != null) {
return getCredentials().getApiKey();
} else {
PluginImpl p = PluginImpl.get();
if (p.isReuseSauceAuth()) {
com.saucelabs.rest.Credential storedCredentials;
try {
storedCredentials = new com.saucelabs.rest.Credential();
return storedCredentials.getKey();
} catch (IOException e) {
logger.log(Level.WARNING, "Error retrieving credentials", e);
}
} else {
return Secret.toString(p.getApiKey());
}
}
return "";
}

public String getSeleniumHost() {
return seleniumHost;
}
@@ -348,21 +396,8 @@ public ITunnelHolder call() throws IOException {
private int port;

public SauceConnectStarter(BuildListener listener, int port) throws IOException {
if (getCredentials() != null) {
this.username = getCredentials().getUsername();
this.key = getCredentials().getApiKey();
} else {
PluginImpl p = PluginImpl.get();
if (p.isReuseSauceAuth()) {
com.saucelabs.rest.Credential storedCredentials = new com.saucelabs.rest.Credential();
this.username = storedCredentials.getUsername();
this.key = storedCredentials.getKey();
} else {
this.username = p.getUsername();
this.key = Secret.toString(p.getApiKey());
}
}

this.username = getUserName();
this.key = getApiKey();
this.listener = listener;
this.port = port;
}

0 comments on commit a78f784

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