Junit test : seed job to maven Job DSL

44 views
Skip to first unread message

Charles Moulliard

unread,
Dec 17, 2020, 5:54:39 AM12/17/20
to Jenkins Users
Hi

I created a Junit test case which is available here:  https://github.com/ch007m/jenkins-job-dsl/blob/31efa049a95c333a8dba9b01ff2aa281b3520e34/src/test/java/dev/snowdrop/MavenJobDSLTest.java#L25-L53 where a seed job is created to populate a mavenJob using the DSL groovy file provided 

But when it is executed; the job build fails and reports this error

Legacy code started this job.  No cause information is available
Running as SYSTEM
Building in workspace /var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/j h5344303144116520886/workspace/test0
Processing provided DSL script
ERROR: java.io.IOException: Unable to read /var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/j h5344303144116520886/jobs/mvn-spring-boot-rest-http/config.xml
Finished: FAILURE

The error comes from the fact that the job "mvn-spring-boot-rest-http" has not been created under the "jobs" folder. the jobs folder only contains a "test0" folder.

How can I investigate the problem and fix that ? 

If I check the config.xml file generated, it looks good (vs same config.xml file created using the UI)

<?xml version='1.1' encoding='UTF-8'?>
<project>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>false</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <javaposse.jobdsl.plugin.ExecuteDslScripts>
      <scriptText>mavenJob(&apos;mvn-spring-boot-rest-http&apos;) {
    description &apos;A Maven Job compiling the project Spring Boot Rest HTTP Example&apos;

    parameters {
        gitParameter {
            name &apos;SELECTED_TAG&apos;
            description &apos;The Git tag to checkout&apos;
            type &apos;PT_TAG&apos;
            defaultValue &apos;2.3.4-2&apos;
            branch &apos;&apos;
            branchFilter &apos;origin/(.*)&apos;
            quickFilterEnabled false
            selectedValue &apos;DEFAULT&apos;
            sortMode &apos;DESCENDING_SMART&apos;
            tagFilter &apos;*&apos;
            useRepository &apos;.*rest-http-example.git&apos;
            listSize &apos;10&apos;
        }
    }

    scm {
        git {
            remote {
                // branch(&apos;$SELECTED_TAG&apos;)
                branch(&apos;2.3.4-2&apos;)
            }
        }
    }
    rootPOM &apos;pom.xml&apos;
    goals &apos;clean install&apos;
}</scriptText>
      <usingScriptText>true</usingScriptText>
      <sandbox>false</sandbox>
      <ignoreExisting>false</ignoreExisting>
      <ignoreMissingFiles>false</ignoreMissingFiles>
      <failOnMissingPlugin>false</failOnMissingPlugin>
      <failOnSeedCollision>false</failOnSeedCollision>
      <unstableOnDeprecation>false</unstableOnDeprecation>
      <removedJobAction>IGNORE</removedJobAction>
      <removedViewAction>IGNORE</removedViewAction>
      <removedConfigFilesAction>IGNORE</removedConfigFilesAction>
      <lookupStrategy>JENKINS_ROOT</lookupStrategy>
    </javaposse.jobdsl.plugin.ExecuteDslScripts>
  </builders>
  <publishers/>
  <buildWrappers/>
</project>

excepted that the config.xml created from the UI includes this additional parameter

<javaposse.jobdsl.plugin.ExecuteDslScripts plugin="job...@1.77">

Cheers

Charles

Charles Moulliard

unread,
Dec 17, 2020, 6:38:11 AM12/17/20
to Jenkins Users
FYI: I can, of course, create the job and build it using the `config.xml` generated on a jenkins instance running locally -> `java -jar jenkins-cli.jar -s http://localhost:8080 create-job maven-seed-job2 < seed-maven-job2.xml`

So I suspect a problem with the Job DSL Plugin when the job build is scheduled with the "ExecuteDslScripts". But If no stacktrace is reported, then it will very hard to figure out the issue
Reply all
Reply to author
Forward
0 new messages