red888
red888

Reputation: 31560

Is there a way to see the actual xml generated by the Jenkins job dsl when using the Jenkins test harness?

I'm trying to use the Jenkins test harness to test Jenkins job DSL jobs: https://www.testcookbook.com/book/groovy/jenkins/intro-testing-job-dsl.html

Is there a way to output and validate the XML that the job DSL will generate for configuring Jenkins jobs with the test harness? I have not found any examples.

I want to validate the actual config that the job DSL will generate in the tests.

How do DSL functions like "folder()" or "multibranchPipelineJob()" work? Can they return the XML they are going to generate when called? When running the test harness is it actually writing the job configs to the local Jenkins instance and if so can I retrieve that XML and validate it in a Spock test?

Upvotes: 0

Views: 693

Answers (2)

link89
link89

Reputation: 1763

Yes you can, Jenkins community provides a package for testing job-dsl locally, all you need to do is to download it and run against your job-dsl script by executing the following command line.

# replace the @version@ to the actual version number, 1,18 for example
curl -O https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/job-dsl-core/@version@/job-dsl-core-@[email protected]

java -jar job-dsl-core-@[email protected] sample.dsl.groovy

More detail could be found here: https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/User-Power-Moves.md

BTW there is a command tool can simplify the task: https://github.com/link89/jenkins-fire-cli

jenkins-fire-cli dsl sample.dsl.groovy

Upvotes: 1

Dmitriy Tarasevich
Dmitriy Tarasevich

Reputation: 1242

All job config files are stored in jenkins master host in $JENKINS_HOME/jobs/$YOUR_JOB_NAME/config.xml file.

Upvotes: 0

Related Questions