Skip to content
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

[JENKINS-74871] Fix the broken jelly view #147

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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 @@ -32,8 +32,11 @@ THE SOFTWARE.
<f:invisibleEntry>
<f:textbox field="failedValidationMessage" value="${it.failedValidationMessage}"/>
</f:invisibleEntry>
<f:entry title="${h.xmlEscape(it.name)}" description="${it.formattedDescription}" field="defaultValue">
<f:textbox value="${it.defaultValue}" checkUrl="${it.descriptor.descriptorFullUrl}/validate"
checkDependsOn="regex failedValidationMessage"/>
<f:entry title="${h.xmlEscape(it.name)}" description="${it.formattedDescription}">
<div name="parameter" description="${it.formattedDescription}">
<input type="hidden" name="name" value="${it.name}"/>
<f:textbox name="value" value="${it.defaultValue}" checkUrl="${it.descriptor.descriptorFullUrl}/validate"
checkDependsOn="../regex ../failedValidationMessage"/>
</div>
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
package hudson.plugins.validating_string_parameter;

import hudson.Functions;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import org.htmlunit.html.DomNode;
import org.htmlunit.html.HtmlButton;
import org.htmlunit.html.HtmlPage;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

Expand All @@ -29,4 +45,30 @@ public void pipeline() throws Exception {
r.buildAndAssertSuccess(p);
assertThat(p.getProperty(ParametersDefinitionProperty.class), is(notNullValue()));
}

@Test
public void freestyle() throws Exception {
FreeStyleProject p = r.createProject(FreeStyleProject.class, "fs");
p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo test") : new Shell("echo test"));

ValidatingStringParameterDefinition def = new ValidatingStringParameterDefinition("name", "defVal", "\\w+", "Value must match the following pattern: \\w+");
p.addProperty(new ParametersDefinitionProperty(def));

try (JenkinsRule.WebClient wc = r.createWebClient()) {
wc.setThrowExceptionOnFailingStatusCode(false);
HtmlPage htmlPage = wc.goTo("job/fs/build");
HtmlButton buildButton = htmlPage.querySelector(".jenkins-button--primary");
buildButton.click();
}

r.waitUntilNoActivity();
List<ParameterValue> parameters = p.getLastSuccessfulBuild().getAction(ParametersAction.class).getParameters();
assertThat(parameters, is(not(empty())));
ParameterValue parameterValue = parameters.get(0);
assertThat(parameterValue, is(instanceOf(ValidatingStringParameterValue.class)));
ValidatingStringParameterValue val = (ValidatingStringParameterValue) parameterValue;
assertThat(val.getRegex(), is(equalTo("\\w+")));
assertThat(val.getValue(), is(equalTo("defVal")));
assertThat(val.getName(), is(equalTo("name")));
}
}