Skip to content

Commit a66c11e

Browse files
committed
Fix urls when 2 clouds with same name exist
When 2 clouds are created with the same name, then accessing the second cloud produces a different url.
1 parent fdf986d commit a66c11e

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

core/src/main/java/hudson/slaves/Cloud.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ public String getDisplayName() {
140140
* @return Jenkins relative URL.
141141
*/
142142
public @NonNull String getUrl() {
143-
return "cloud/" + Util.rawEncode(name) + "/";
143+
if (Jenkins.get().getCloud(name) != this) { // this cloud is not the first occurrence with this name
144+
return "cloud/cloudByIndex/" + Jenkins.get().clouds.indexOf(this) + "/";
145+
} else {
146+
return "cloud/" + Util.rawEncode(name) + "/";
147+
}
144148
}
145149

146150
@Override

core/src/main/java/jenkins/agents/CloudSet.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ public ManagementLink getManagementLink() {
113113
@Restricted(DoNotUse.class) // stapler
114114
public String getCloudUrl(StaplerRequest2 request, Jenkins jenkins, Cloud cloud) {
115115
String context = Functions.getNearestAncestorUrl(request, jenkins);
116-
if (Jenkins.get().getCloud(cloud.name) != cloud) { // this cloud is not the first occurrence with this name
117-
return context + "/cloud/cloudByIndex/" + getClouds().indexOf(cloud) + "/";
118-
} else {
119-
return context + "/" + cloud.getUrl();
120-
}
116+
return context + "/" + cloud.getUrl();
121117
}
122118

123119
/**

core/src/main/resources/hudson/slaves/Cloud/sidepanel.jelly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ THE SOFTWARE.
2727
<l:header />
2828
<l:side-panel>
2929
<l:tasks>
30-
<j:set var="url" value="${h.getNearestAncestorUrl(request2,it)}"/>
31-
<l:task contextMenu="false" href="${url}/" icon="symbol-computer" title="${%Status}"/>
32-
<l:task href="${url}/configure" icon="symbol-settings"
30+
<j:set var="url" value="${rootURL}/${it.url}"/>
31+
<l:task contextMenu="false" href="${url}" icon="symbol-computer" title="${%Status}"/>
32+
<l:task href="${url}configure" icon="symbol-settings"
3333
title="${app.hasPermission(app.ADMINISTER) ? '%Configure' : '%View Configuration'}"/>
3434
<l:delete permission="${app.ADMINISTER}" title="${%Delete Cloud}" message="${%delete.cloud(it.displayName)}" urlPrefix="${url}"/>
3535
<t:actions />

core/src/main/resources/jenkins/agents/CloudSet/index.jelly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ THE SOFTWARE.
6464
</td>
6565
<td>
6666
<input type="hidden" name="name" value="${cloud.name}" />
67-
<a href="${it.getCloudUrl(request2,app,cloud)}" class="jenkins-table__link model-link inside">${cloud.name}</a>
67+
<a href="../${cloud.url}" class="jenkins-table__link model-link inside">${cloud.name}</a>
6868
</td>
6969
<td class="jenkins-table__cell--tight">
7070
<div class="jenkins-table__cell__button-wrapper">
71-
<a href="${it.getCloudUrl(request2,app,cloud)}configure" class="jenkins-button">
71+
<a href="../${cloud.url}configure" class="jenkins-button">
7272
<l:icon src="symbol-settings"/>
7373
</a>
7474
</div>

core/src/main/resources/lib/layout/delete.jelly

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ THE SOFTWARE.
7575

7676
<j:set var="url" value="doDelete" />
7777
<j:if test="${attrs.urlPrefix != null}">
78-
<j:set var="url" value="${urlPrefix}/doDelete" />
78+
<j:set var="basePrefix" value="${urlPrefix.endsWith('/') ? urlPrefix.substring(0, urlPrefix.length() - 1) : urlPrefix}" />
79+
<j:set var="url" value="${basePrefix}/doDelete" />
7980
</j:if>
8081

8182

0 commit comments

Comments
 (0)