Skip to content

Commit

Permalink
[JENKINS-60138] Fixed job links for jobs in folders (#62)
Browse files Browse the repository at this point in the history
Use getUrl() instead of reinventing its logic in jelly
  • Loading branch information
balakine authored Feb 19, 2024
1 parent ccf008e commit d7bd6e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ public JobBuildSearchResult createJobBuildSearchResult(Run<?, ?> build){
public JobBuildSearchResult createJobBuildSearchResult(JobBuildResult r){
boolean isJobAccessible = false;
boolean isBuildAccessible = false;
String jobUrl = "";

Job targetJob = ((Job) Jenkins.getInstance().getItemByFullName(r.getJobName()));
// Link to job will be provided only if job has not been deleted/renamed
if(targetJob != null){
isJobAccessible = true;
jobUrl = targetJob.getUrl();
if(targetJob.getBuildByNumber(r.getBuildNumber()) != null){
// Link to build infos will be provided only if build result has not been purged
// @see issue #7240
isBuildAccessible = true;
}
}

return new JobBuildSearchResult(r, isJobAccessible, isBuildAccessible);
return new JobBuildSearchResult(r, isJobAccessible, isBuildAccessible, jobUrl);

Check warning on line 53 in src/main/java/hudson/plugins/global_build_stats/JobBuildResultFactory.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 39-53 are not covered by tests
}

public static String extractUserNameIn(Run<?, ?> build){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public class JobBuildSearchResult extends JobBuildResult {
private boolean jobAccessible;
// Will be true if isJobAccessible is true AND build result has not been deleted
private boolean buildAccessible;
private String jobUrl;

public JobBuildSearchResult(JobBuildResult decoree, boolean isJobAccessible, boolean isBuildAccessible){
public JobBuildSearchResult(JobBuildResult decoree, boolean isJobAccessible, boolean isBuildAccessible, String jobUrl) {
super(decoree.getResult(), decoree.getJobName(), decoree.getBuildNumber(), decoree.getBuildDate(),
decoree.getDuration(), decoree.getNodeName(), decoree.getUserName());
this.jobAccessible = isJobAccessible;
this.buildAccessible = isBuildAccessible;
this.jobUrl = jobUrl;
}

public boolean isJobAccessible() {
Expand All @@ -33,4 +35,8 @@ public boolean isBuildAccessible() {
public String getDurationString(){
return Util.getTimeSpanString(getDuration());
}

public String getJobUrl() {
return jobUrl;

Check warning on line 40 in src/main/java/hudson/plugins/global_build_stats/model/JobBuildSearchResult.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 24-40 are not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<td class="pane">
<j:choose>
<j:when test="${jobResult.jobAccessible}">
<a href="${rootURL}/job/${jobResult.jobName}/">${jobResult.jobName}</a>
<a href="${rootURL}/${jobResult.jobUrl}">${jobResult.jobName}</a>
</j:when>
<j:otherwise>
${jobResult.jobName}
Expand All @@ -226,8 +226,8 @@
<td class="pane">
<j:choose>
<j:when test="${jobResult.buildAccessible}">
<a href="${rootURL}/job/${jobResult.jobName}/${jobResult.buildNumber}/console"><l:icon class="icon-terminal icon-lg"/><br/></a>
<a href="${rootURL}/job/${jobResult.jobName}/${jobResult.buildNumber}/">#${jobResult.buildNumber}</a>
<a href="${rootURL}/${jobResult.jobUrl}${jobResult.buildNumber}/console"><l:icon class="icon-terminal icon-lg"/><br/></a>
<a href="${rootURL}/${jobResult.jobUrl}${jobResult.buildNumber}/">#${jobResult.buildNumber}</a>
</j:when>
<j:otherwise>
#${jobResult.buildNumber}
Expand All @@ -237,7 +237,7 @@
<td class="pane">
<j:choose>
<j:when test="${jobResult.buildAccessible}">
<a href="${rootURL}/job/${jobResult.jobName}/${jobResult.buildNumber}/"><i:formatDate value="${jobResult.buildDate.time}" type="both" dateStyle="medium" timeStyle="medium"/></a>
<a href="${rootURL}/${jobResult.jobUrl}${jobResult.buildNumber}/"><i:formatDate value="${jobResult.buildDate.time}" type="both" dateStyle="medium" timeStyle="medium"/></a>
</j:when>
<j:otherwise>
<i:formatDate value="${jobResult.buildDate.time}" type="both" dateStyle="medium" timeStyle="medium"/>
Expand Down

0 comments on commit d7bd6e3

Please sign in to comment.