Permalink
Browse files

[FIXED JENKINS-47559] Don't do full validation for non-conditions

  • Loading branch information...
abayer committed Oct 23, 2017
1 parent 47f97fb commit 114588a7be038d48177c80d9f05e0a7e017c9501
@@ -871,7 +871,7 @@ class ModelParser implements Parser {
def mc = matchMethodCall(st);
if (mc == null) {
// Not sure of a better way to deal with this - it's a full-on parse-time failure.
errorCollector.error(condition, Messages.ModelParser_ExpectedStep());
errorCollector.error(condition, Messages.ModelParser_ExpectedWhen());
return condition
};

@@ -210,6 +210,11 @@ class ModelValidatorImpl implements ModelValidator {
boolean valid = true
def allNames = DeclarativeStageConditionalDescriptor.allNames()

// Short-circuit in cases where the condition didn't parse right in the first place.
if (condition?.name == null) {
return false
}

if (!(condition.name in allNames)) {
errorCollector.error(condition, Messages.ModelValidatorImpl_UnknownWhenConditional(condition.name, allNames.join(", ")))
valid = false
@@ -762,4 +762,12 @@ public void bareDollarCurly() throws Exception {
Messages.ModelParser_BareDollarCurly("${FOO}"))
.go();
}

@Issue("JENKINS-47559")
@Test
public void whenContainingNonCondition() throws Exception {
expectError("whenContainingNonCondition")
.logContains(Messages.ModelParser_ExpectedWhen())
.go();
}
}
@@ -0,0 +1,44 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent any

parameters {
stringParam(name: 'someParam', defaultValue: 'foo', description: '')
}

stages {

stage('Fix Me') {
when {
params.someParam == 'CI'
}

steps {
echo "Hello World"
}
}
}
}

0 comments on commit 114588a

Please sign in to comment.