Skip to content

Commit 23895f4

Browse files
authored
forward compatibility with core-8418 (#522)
* forward compatibility with core-8418 jenkinsci/jenkins#8418 * revert pom change * check via versionnumber
1 parent 2b33362 commit 23895f4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/SecureGroovyScriptTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import hudson.security.Permission;
4747
import hudson.tasks.BuildStepDescriptor;
4848
import hudson.tasks.Publisher;
49+
import hudson.util.VersionNumber;
4950
import java.io.File;
5051
import java.io.IOException;
5152
import java.net.URISyntaxException;
@@ -96,6 +97,17 @@ public class SecureGroovyScriptTest {
9697

9798
@Rule public TemporaryFolder tmpFolderRule = new TemporaryFolder();
9899

100+
private void addPostBuildAction(HtmlPage page) throws IOException {
101+
String displayName = r.jenkins.getExtensionList(BuildStepDescriptor.class).get(TestGroovyRecorder.DescriptorImpl.class).getDisplayName();
102+
if (Jenkins.getVersion().isOlderThan(new VersionNumber("2.422"))) {
103+
page.getAnchorByText(displayName).click();
104+
} else {
105+
HtmlForm config = page.getFormByName("config");
106+
r.getButtonByCaption(config, displayName).click();
107+
}
108+
109+
}
110+
99111
/**
100112
* Basic approval test where the user doesn't have ADMINISTER privs but has unchecked
101113
* the sandbox checkbox. Should result in script going to pending approval.
@@ -116,7 +128,7 @@ public class SecureGroovyScriptTest {
116128
HtmlPage page = wc.getPage(p, "configure");
117129
HtmlForm config = page.getFormByName("config");
118130
HtmlFormUtil.getButtonByCaption(config, "Add post-build action").click(); // lib/hudson/project/config-publishers2.jelly
119-
page.getAnchorByText(r.jenkins.getExtensionList(BuildStepDescriptor.class).get(TestGroovyRecorder.DescriptorImpl.class).getDisplayName()).click();
131+
addPostBuildAction(page);
120132
wc.waitForBackgroundJavaScript(10000);
121133
List<HtmlTextArea> scripts = config.getTextAreasByName("_.script");
122134
// Get the last one, because previous ones might be from Lockable Resources during PCT.
@@ -188,7 +200,7 @@ public class SecureGroovyScriptTest {
188200
HtmlPage page = wc.getPage(p, "configure");
189201
HtmlForm config = page.getFormByName("config");
190202
HtmlFormUtil.getButtonByCaption(config, "Add post-build action").click(); // lib/hudson/project/config-publishers2.jelly
191-
page.getAnchorByText(r.jenkins.getExtensionList(BuildStepDescriptor.class).get(TestGroovyRecorder.DescriptorImpl.class).getDisplayName()).click();
203+
addPostBuildAction(page);
192204
wc.waitForBackgroundJavaScript(10000);
193205
List<HtmlTextArea> scripts = config.getTextAreasByName("_.script");
194206
// Get the last one, because previous ones might be from Lockable Resources during PCT.
@@ -231,7 +243,7 @@ public class SecureGroovyScriptTest {
231243
HtmlPage page = wc.getPage(p, "configure");
232244
HtmlForm config = page.getFormByName("config");
233245
HtmlFormUtil.getButtonByCaption(config, "Add post-build action").click(); // lib/hudson/project/config-publishers2.jelly
234-
page.getAnchorByText(r.jenkins.getExtensionList(BuildStepDescriptor.class).get(TestGroovyRecorder.DescriptorImpl.class).getDisplayName()).click();
246+
addPostBuildAction(page);
235247
wc.waitForBackgroundJavaScript(10000);
236248
List<HtmlTextArea> scripts = config.getTextAreasByName("_.script");
237249
// Get the last one, because previous ones might be from Lockable Resources during PCT.
@@ -1303,7 +1315,7 @@ public void testScriptAtFieldInitializers() throws Exception {
13031315
HtmlPage page = wc.getPage(p, "configure");
13041316
HtmlForm config = page.getFormByName("config");
13051317
HtmlFormUtil.getButtonByCaption(config, "Add post-build action").click(); // lib/hudson/project/config-publishers2.jelly
1306-
page.getAnchorByText(r.jenkins.getExtensionList(BuildStepDescriptor.class).get(TestGroovyRecorder.DescriptorImpl.class).getDisplayName()).click();
1318+
addPostBuildAction(page);
13071319
wc.waitForBackgroundJavaScript(10000);
13081320
List<HtmlTextArea> scripts = config.getTextAreasByName("_.script");
13091321
// Get the last one, because previous ones might be from Lockable Resources during PCT.

0 commit comments

Comments
 (0)