Skip to content

Instantly share code, notes, and snippets.

@clifford-github
Created December 10, 2013 13:35
Show Gist options
  • Save clifford-github/7890657 to your computer and use it in GitHub Desktop.
Save clifford-github/7890657 to your computer and use it in GitHub Desktop.
get complete absolute url to a build run
/**
* returns the complete url to a build run
* e.g. http://localhost:8080/job/test/5/
* @param build
* @return build run url as String
*/
private String getAbsoluteBuildUrl(AbstractBuild build) {
return getBaseUrl() + build.getUrl();
}
/**
* returns the value that is configured in
* Manage Jenkins -> Configure System -> Jenkins URL
* e.g. http://localhost:8080/
* After new installation this value has to be changed once
* to have an effect.
* @return base url as String
*/
private String getBaseUrl() {
final String rootUrl = Jenkins.getInstance().getRootUrl();
if (StringUtils.isNotEmpty(rootUrl)) {
return rootUrl;
}
return Jenkins.getInstance().getRootUrlFromRequest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment