Skip to content
Permalink
Browse files

[JENKINS-49387][JENKINS-49520] - Validation errors (#3292)

* Fixes for validation

* Fix for an empty agent.nExecutors
  • Loading branch information...
ksenia-nenasheva authored and oleg-nenashev committed Feb 18, 2018
1 parent 54431a1 commit 5c8cc45900bf8d78058cecd471840bdbc88215d3
@@ -67,6 +67,7 @@
import jenkins.util.ContextResettingExecutorService;
import jenkins.security.MasterToSlaveCallable;

import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.kohsuke.accmod.Restricted;
@@ -1473,7 +1474,7 @@ public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOE
}

String nExecutors = req.getSubmittedForm().getString("numExecutors");
if (Integer.parseInt(nExecutors)<=0) {
if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) {
throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors");
}

@@ -33,7 +33,7 @@ THE SOFTWARE.
</f:entry>

<f:entry title="${%# of executors}" field="numExecutors">
<f:number clazz="positive-number" min="1" step="1" default="1"/>
<f:number clazz="positive-number-required" min="1" step="1" default="1"/>
</f:entry>

<f:entry title="${%Remote root directory}" field="remoteFS">
@@ -42,7 +42,7 @@ THE SOFTWARE.
-->

<f:entry title="${%# of executors}" field="numExecutors">
<f:number clazz="non-negative-number" min="0" step="1"/>
<f:number clazz="non-negative-number-required" min="0" step="1"/>
</f:entry>

<f:entry title="${%Labels}" field="labelString">
@@ -3,7 +3,7 @@ package jenkins.model.MasterBuildConfiguration
def f=namespace(lib.FormTagLib)

f.entry(title:_("# of executors"), field:"numExecutors") {
f.number(clazz:"non-negative-number", min:0, step:1)
f.number(clazz:"non-negative-number-required", min:0, step:1)
}
f.entry(title:_("Labels"),field:"labelString") {
f.textbox()
@@ -694,11 +694,17 @@ var jenkinsRules = {
"INPUT.required" : function(e) { registerRegexpValidator(e,/./,"Field is required"); },

// validate form values to be an integer
"INPUT.number" : function(e) { registerRegexpValidator(e,/^\-?(\d+)$/,"Not an integer"); },
"INPUT.non-negative-number" : function(e) {
"INPUT.number" : function(e) { registerRegexpValidator(e,/^(\d+|)$/,"Not an integer"); },
"INPUT.number-required" : function(e) { registerRegexpValidator(e,/^\-?(\d+)$/,"Not an integer"); },

"INPUT.non-negative-number-required" : function(e) {
registerRegexpValidator(e,/^\d+$/,"Not a non-negative number");
},

"INPUT.positive-number" : function(e) {
registerRegexpValidator(e,/^(\d*[1-9]\d*|)$/,"Not a positive integer");
},
"INPUT.positive-number-required" : function(e) {
registerRegexpValidator(e,/^[1-9]\d*$/,"Not a positive integer");
},

0 comments on commit 5c8cc45

Please sign in to comment.
You can’t perform that action at this time.