Skip to content

getting jenkins root url from Jenkins class instance #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hudson.model.Cause;
import hudson.model.Result;
import hudson.model.TaskListener;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;

import java.io.IOException;
Expand Down Expand Up @@ -49,15 +50,22 @@ public void onCompleted(AbstractBuild build, TaskListener listener) {
return;
}
Result result = build.getResult();
JenkinsLocationConfiguration globalConfig = new JenkinsLocationConfiguration();
String rootUrl = globalConfig.getUrl();
String buildUrl = "";
if (rootUrl == null) {
buildUrl = " PLEASE SET JENKINS ROOT URL FROM GLOBAL CONFIGURATION " + build.getUrl();
}
else {
buildUrl = rootUrl + build.getUrl();
// JenkinsLocationConfiguration globalConfig = new JenkinsLocationConfiguration();
String rootUrl = "";
String buildUrl;
Jenkins jenkinsInstance = Jenkins.getInstance();
if (jenkinsInstance != null ){
rootUrl = jenkinsInstance.getRootUrl();
if (!rootUrl.isEmpty()){
buildUrl = rootUrl + build.getUrl();
}else{
buildUrl = "Jenkins instance root URL is empty "+ build.getUrl();
Copy link

@goostleek goostleek Dec 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous message (PLEASE SET JENKINS ROOT URL FROM GLOBAL CONFIGURATION) is more valuable for the user. It says precisely to adjust Jenkins configuration to get the proper build URL.

}
}else{
buildUrl = "Jenkins instance is NULL "+ build.getUrl();
}

logger.info("StashBuilds: rootUrl: " + rootUrl + ", buildUrl: " + buildUrl);
repository.deletePullRequestComment(cause.getPullRequestId(), cause.getBuildStartCommentId());

String additionalComment = "";
Expand Down