Skip to content

Instantly share code, notes, and snippets.

@msteiger
Created September 23, 2016 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msteiger/8c7ce6fd413b160a1e9642253fc472e7 to your computer and use it in GitHub Desktop.
Save msteiger/8c7ce6fd413b160a1e9642253fc472e7 to your computer and use it in GitHub Desktop.
// This gem executes a single JUnit test conditionally. If the machine name contains a sub-string
// such as "dev", it will always be successful
public class MyTests {
final static private String[] JenkinsServerNameParts = new String[] { "da-build", "master", "soap", "dev" };
@Test
public void startNightVision() {
if(isRunOnJenkinsServer())
return;
...
}
protected boolean isRunOnJenkinsServer() {
try {
String hostName = InetAddress.getLocalHost().getHostName().toLowerCase();
for(String serverNamePart : JenkinsServerNameParts) {
if(hostName.contains(serverNamePart)) {
return true;
}
}
return false;
}
catch (UnknownHostException e) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment