Skip to content

Advanced XML manipulation #71

@realdadfish

Description

@realdadfish

I have an XML template that contains a single publisher XML snippet that I want to dynamically expand to multiple instances of the same snippet, but of course with different configuration for each.

While I figured out that I can easily add new nodes via the leftShift operator on the projectXml, I don't seem to be able to override the child elements of the just copied nodes, because they're not yet visible.

I came up with the following workaround, but I found that rather ugly:

jenkins {
    templates {
        hockeyupload_bare {
            xml file('path/to/hockeyupload.xml')
        }
        hockeyupload_multiplied {
            xml jenkins.templates.hockeyupload_bare.override { projectXml ->
                if (project.ext.hockeyAppIds.size() > 1) {
                    (1..project.ext.hockeyAppIds.size() - 1).each {
                        projectXml.publishers << projectXml.publishers["hockeyapp.HockeyappRecorder"]
                    }
                }
            }
        }
        hockeyupload {
            xml templates.hockeyupload_multiplied.override { projectXml ->
                def item = 0
                project.ext.hockeyAppIds.each { hockeyAppid ->
                    projectXml.publishers["hockeyapp.HockeyappRecorder"][item].applications["hockeyapp.HockeyappApplication"].with {
                        // specific overrides ..
                    }
                    ++item
                }
            }
        }
    }
}

Am I missing something or should this plugin somehow gain "flush" support to avoid these kind of hacks?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions