Skip to content

Commit

Permalink
[JENKINS-49387][JENKINS-49520] - Validation errors (#3292)
Browse files Browse the repository at this point in the history
* Fixes for validation

* Fix for an empty agent.nExecutors

(cherry picked from commit 5c8cc45)
  • Loading branch information
ksenia-nenasheva authored and olivergondza committed Feb 28, 2018
1 parent dd3ddf3 commit 2ad96a3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/Computer.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down
Expand Up @@ -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">
Expand Down
Expand Up @@ -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">
Expand Down
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions war/src/main/webapp/scripts/hudson-behavior.js
Expand Up @@ -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");
},

Expand Down

0 comments on commit 2ad96a3

Please sign in to comment.