Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-42498] Failure test for JENKINS-42498 serialization
- Loading branch information
Showing
9 changed files
with
540 additions
and
0 deletions.
There are no files selected for viewing
198 changes: 198 additions & 0 deletions
198
...ition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/SerializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.pipeline.modeldefinition; | ||
|
||
import hudson.model.BooleanParameterDefinition; | ||
import hudson.model.Describable; | ||
import hudson.model.ParametersDefinitionProperty; | ||
import hudson.model.Slave; | ||
import hudson.slaves.EnvironmentVariablesNodeProperty; | ||
import hudson.tasks.LogRotator; | ||
import hudson.triggers.TimerTrigger; | ||
import hudson.triggers.Trigger; | ||
import jenkins.model.BuildDiscarder; | ||
import jenkins.model.BuildDiscarderProperty; | ||
import jenkins.plugins.git.GitSCMSource; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty; | ||
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries; | ||
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration; | ||
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever; | ||
import org.jenkinsci.plugins.workflow.pickles.Pickle; | ||
import org.jenkinsci.plugins.workflow.support.pickles.SingleTypedPickleFactory; | ||
import org.jenkinsci.plugins.workflow.support.pickles.XStreamPickle; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.TestExtension; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Note that in practice, only {@link #serializationEnvGString} fails, but it felt best to cover the other possible | ||
* cases as well. | ||
*/ | ||
@Issue("JENKINS-42498") | ||
public class SerializationTest extends AbstractModelDefTest { | ||
|
||
private static Slave s; | ||
|
||
@BeforeClass | ||
public static void setUpAgent() throws Exception { | ||
s = j.createOnlineSlave(); | ||
s.setNumExecutors(4); | ||
s.setLabelString("some-label docker test"); | ||
s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"))); | ||
} | ||
|
||
@Test | ||
public void serializationEnvGString() throws Exception { | ||
expect("serializationEnvGString") | ||
.logContains("[Pipeline] { (foo)", | ||
"_UNDERSCORE is VALID") | ||
.logMatches("FOO is test\\d+foo") | ||
.go(); | ||
} | ||
|
||
@Test | ||
public void serializationParametersGString() throws Exception { | ||
WorkflowRun b = expect("serializationParametersGString") | ||
.logContains("[Pipeline] { (foo)", "hello") | ||
.logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") | ||
.go(); | ||
|
||
WorkflowJob p = b.getParent(); | ||
|
||
ParametersDefinitionProperty pdp = p.getProperty(ParametersDefinitionProperty.class); | ||
assertNotNull(pdp); | ||
|
||
assertEquals(1, pdp.getParameterDefinitions().size()); | ||
assertEquals(BooleanParameterDefinition.class, pdp.getParameterDefinitions().get(0).getClass()); | ||
BooleanParameterDefinition bpd = (BooleanParameterDefinition) pdp.getParameterDefinitions().get(0); | ||
assertEquals(p.getDisplayName(), bpd.getName()); | ||
assertTrue(bpd.isDefaultValue()); | ||
} | ||
|
||
@Test | ||
public void serializationAgentGString() throws Exception { | ||
expect("serializationAgentGString") | ||
.logContains("[Pipeline] { (foo)", "ONAGENT=true") | ||
.go(); | ||
} | ||
|
||
@Test | ||
public void serializationAgentNestedGString() throws Exception { | ||
expect("serializationAgentNestedGString") | ||
.logContains("[Pipeline] { (foo)", "ONAGENT=true") | ||
.go(); | ||
} | ||
|
||
@Test | ||
public void serializationJobPropsGString() throws Exception { | ||
WorkflowRun b = expect("serializationJobPropsGString") | ||
.logContains("[Pipeline] { (foo)", "hello") | ||
.logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") | ||
.go(); | ||
|
||
WorkflowJob p = b.getParent(); | ||
|
||
BuildDiscarderProperty bdp = p.getProperty(BuildDiscarderProperty.class); | ||
assertNotNull(bdp); | ||
BuildDiscarder strategy = bdp.getStrategy(); | ||
assertNotNull(strategy); | ||
assertEquals(LogRotator.class, strategy.getClass()); | ||
LogRotator lr = (LogRotator) strategy; | ||
assertEquals(Integer.parseInt(p.getDisplayName().substring(4)), lr.getNumToKeep()); | ||
} | ||
|
||
@Test | ||
public void serializationLibrariesGString() throws Exception { | ||
otherRepo.init(); | ||
otherRepo.write("vars/myecho.groovy", "def call() {echo 'something special'}"); | ||
otherRepo.write("vars/myecho.txt", "Says something very special!"); | ||
otherRepo.git("add", "vars"); | ||
otherRepo.git("commit", "--message=init"); | ||
LibraryConfiguration firstLib = new LibraryConfiguration("echo-utils", | ||
new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true))); | ||
|
||
thirdRepo.init(); | ||
thirdRepo.write("vars/whereFrom.groovy", "def call() {echo 'from another library'}"); | ||
thirdRepo.write("vars/whereFrom.txt", "Says where it's from!"); | ||
thirdRepo.git("add", "vars"); | ||
thirdRepo.git("commit", "--message=init"); | ||
LibraryConfiguration secondLib = new LibraryConfiguration("test", | ||
new SCMSourceRetriever(new GitSCMSource(null, thirdRepo.toString(), "", "*", "", true))); | ||
secondLib.setDefaultVersion("master"); | ||
GlobalLibraries.get().setLibraries(Arrays.asList(firstLib, secondLib)); | ||
|
||
expect("serializationLibrariesGString") | ||
.logContains("something special", "from another library") | ||
.go(); | ||
} | ||
|
||
@Test | ||
public void serializationTriggersGString() throws Exception { | ||
WorkflowRun b = expect("serializationTriggersGString") | ||
.logContains("[Pipeline] { (foo)", "hello") | ||
.logNotContains("[Pipeline] { (Post Actions)") | ||
.go(); | ||
|
||
WorkflowJob p = b.getParent(); | ||
|
||
PipelineTriggersJobProperty triggersJobProperty = p.getTriggersJobProperty(); | ||
assertNotNull(triggersJobProperty); | ||
assertEquals(1, triggersJobProperty.getTriggers().size()); | ||
TimerTrigger.DescriptorImpl timerDesc = j.jenkins.getDescriptorByType(TimerTrigger.DescriptorImpl.class); | ||
|
||
Trigger trigger = triggersJobProperty.getTriggerForDescriptor(timerDesc); | ||
assertNotNull(trigger); | ||
|
||
assertTrue(trigger instanceof TimerTrigger); | ||
TimerTrigger timer = (TimerTrigger) trigger; | ||
assertEquals("@daily", timer.getSpec()); | ||
} | ||
|
||
@Test | ||
public void serializationWhenBranchGString() throws Exception { | ||
expect("serializationWhenBranchGString") | ||
.logContains("[Pipeline] { (One)", "[Pipeline] { (Two)", "World") | ||
.go(); | ||
} | ||
|
||
@TestExtension | ||
public static class XStreamPickleFactory extends SingleTypedPickleFactory<Describable<?>> { | ||
|
||
@Override protected Pickle pickle(Describable<?> d) { | ||
return new XStreamPickle(d); | ||
} | ||
|
||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
pipeline-model-definition/src/test/resources/serializationAgentGString.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 "${env.JOB_NAME.substring(0, 4)}" | ||
} | ||
stages { | ||
stage("foo") { | ||
steps { | ||
sh('echo ONAGENT=$ONAGENT') | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
41 changes: 41 additions & 0 deletions
41
pipeline-model-definition/src/test/resources/serializationAgentNestedGString.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 { | ||
node { | ||
label "${env.JOB_NAME.substring(0, 4)}" | ||
} | ||
} | ||
stages { | ||
stage("foo") { | ||
steps { | ||
sh('echo ONAGENT=$ONAGENT') | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
51 changes: 51 additions & 0 deletions
51
pipeline-model-definition/src/test/resources/serializationEnvGString.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 { | ||
environment { | ||
FOO = "${env.JOB_NAME}foo" | ||
_UNDERSCORE = "VALID" | ||
} | ||
|
||
agent { | ||
label "some-label" | ||
} | ||
|
||
stages { | ||
stage("foo") { | ||
when { | ||
expression { | ||
return true | ||
} | ||
} | ||
steps { | ||
sh 'echo "FOO is $FOO"' | ||
sh 'echo "_UNDERSCORE is $_UNDERSCORE"' | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
40 changes: 40 additions & 0 deletions
40
pipeline-model-definition/src/test/resources/serializationJobPropsGString.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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 none | ||
options { | ||
buildDiscarder(logRotator(numToKeepStr:"${env.JOB_NAME.substring(4)}")) | ||
} | ||
stages { | ||
stage("foo") { | ||
steps { | ||
echo "hello" | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
Oops, something went wrong.