Permalink
Please sign in to comment.
Browse files
[FIXED JENKINS-48209] Prevent serialization of when expression closure
This shouldn't really matter, in truth - I believe we actually regenerate the whole Root object from scratch on resume, though I could be misremembering. Regardless, even having the when expression closure be transient, the durability test (with when expressions added) still works right. As to why we need to do this in the first place? Because something weird could be out there trying to some non-standard serialization of Describables. Ok, spoiler, there definitely is such a thing, and it does a straight XStream serialization of every Describable. But we use Describables as more than just UI config stuff - we use them for syntax validation and such for our internal extension points, like when conditions. And if that XStream serialization of a when expression with a sh step kicks in, well, all hell breaks loose. This works around that.
- Loading branch information...
Showing
with
112 additions
and 1 deletion.
- +17 −0 ...ition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ASTParserUtils.groovy
- +2 −1 ...src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/ExpressionConditional.java
- +16 −0 ...model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/DurabilityTest.java
- +22 −0 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java
- +55 −0 pipeline-model-definition/src/test/resources/whenExprDurableTask.groovy
@@ -0,0 +1,55 @@ | |||
/* | |||
* The MIT License | |||
* | |||
* Copyright (c) 2017, 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 { | |||
label "here" | |||
} | |||
|
|||
stages { | |||
stage("One") { | |||
steps { | |||
echo "Hello" | |||
} | |||
} | |||
stage("Two") { | |||
when { | |||
expression { | |||
if (isUnix()) { | |||
return sh(script: "echo true", returnStdout: true).trim() == "true" | |||
} else { | |||
return bat(script: "echo true", returnStdout: true).trim() == "true" | |||
} | |||
} | |||
} | |||
steps { | |||
script { | |||
echo "World" | |||
echo "Heal it" | |||
} | |||
|
|||
} | |||
} | |||
} | |||
} |
0 comments on commit
f601a67