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

Is there a way to add "Process Groovy" steps when generating XML? #116

Open
erichzimmermansonos opened this issue May 3, 2022 · 0 comments

Comments

@erichzimmermansonos
Copy link

I am performing a variation on the following test code:

    @Unroll
    void 'test DSL script #file.name can generate Job XML'(File file) {
        given:
        JobManagement jm = new JenkinsJobManagement(
                System.out,
                [SCM_ROOT: '//depot/branches/external_dsl/test',
                 BRANCH_NAME: 'external_dsl',
                 AUTOMATION_ENVIRONMENT: dslConfig.path],
                workspaceRoot)

        when:
        GeneratedItems items = new DslScriptLoader(jm).runScript(file.text)

        then:
        noExceptionThrown()
        assertJobsBuilt(writeOutXmlForGeneratedJobs(items)
        )

        where:
        file << jobFiles
   }

In the actual seed Job, I have an additional groovy file, generateBranchConfigs.groovy, which runs prior to the DSL processing.

I have tried to include the following in my setupSpec() method:

        GroovyShell sh = new GroovyShell()
        String[] shellArgs = []
        File groovyFile = new File("/dsl/src/main/resources/scripts/generateBranchConfigs.groovy")
        sh.run(groovyFile, shellArgs as String[])

However, this approach doesn't have the environment variables that I inject.

Should I set the local environment variables in setupSpec(), or is there a way to configure jm to include the file-generation groovy script?

PS - the code above results in an error, because the Groovy script retrieves null for a required Environment Variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant