Skip to content

Commit

Permalink
Fix dynamic DSL plugins handling in job DSL
Browse files Browse the repository at this point in the history
This commit fixes working with dynamic DSL plugins in job DSL
integration code, namely in promotion actions processing.
  • Loading branch information
Denis Tikhomirov committed Jun 29, 2021
1 parent 03309e6 commit ba862c7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
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 @@ -98,4 +98,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.toString(config, Charset.forName("UTF-8"));
assert content.contains("<javaposse.jobdsl.plugin.ExecuteDslScripts>");
}

}
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')
}
}
}
}
}
}

0 comments on commit ba862c7

Please sign in to comment.