Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-68363] - Fix dynamic DSL plugins handling in job DSL #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,20 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC

private void writeNodes(HierarchicalStreamWriter writer, List<Node> nodes) {
for (Node node : nodes) {
writer.startNode(node.name().toString());
if (node.value() instanceof Collection) {
for (Object subNode : (Collection) node.value()) {
convertNode((Node) subNode, writer);
}
} else {
writer.setValue(node.value().toString());
}
writer.endNode();
writeNode(node, writer);
}
}

private void convertNode(Node node, HierarchicalStreamWriter writer) {
private void writeNode(Node node, HierarchicalStreamWriter writer) {
writer.startNode(node.name().toString());
writeNodeAttributes(node, writer);
if (node.value() instanceof Collection) {
for (Object subNode : (Collection) node.value()) {
convertNode((Node) subNode, writer);
if (subNode instanceof Node) {
writeNode((Node) subNode, writer);
} else {
writer.setValue(subNode.toString());
}
}
} else {
writer.setValue(node.value().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,20 @@ public void testShouldGenerateTheJobWithBuildWrappers() throws Exception {
.matcher(content).find());
}

@Test
public void testShouldGenerateTheDynamicDslJob() throws Exception {
// Given
String dsl = FileUtils.readFileToString(new File("src/test/resources/dynamic-dsl-example-dsl.groovy"));
FreeStyleProject seedJob = j.createFreeStyleProject();
seedJob.getBuildersList().add(createScript(dsl));
// When
QueueTaskFuture<FreeStyleBuild> scheduleBuild2 = seedJob.scheduleBuild2(0);
j.assertBuildStatusSuccess(scheduleBuild2.get());

TopLevelItem item = j.jenkins.getItem("dynamic-dsl-test");
File config = new File(item.getRootDir(), "promotions/Development/config.xml");
String content = Files.readString(config.toPath());
assert content.contains("<javaposse.jobdsl.plugin.ExecuteDslScripts");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn merged to early!

Generally please avoid using an assert for a non boolean primative.

If things fail, you just get a failure, rather it is better to use a higher level framework such as hamcrest so that when things fail you are told that "the needle does not exist in the haystack" (as the haystack can lead you directly to the cause/fix)

}

}
17 changes: 17 additions & 0 deletions src/test/resources/dynamic-dsl-example-dsl.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
freeStyleJob('dynamic-dsl-test') {
properties {
promotions {
promotion {
name('Development')
conditions {
manual('tester')
}
actions {
jobDsl {
scriptText('println test')
}
}
}
}
}
}