Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-45512

Job DSL Unit test fails if there are spaces in the job name

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Labels:
      None
    • Environment:
    • Similar Issues:

      Description

      When running Job DSL unit tests based on https://github.com/jenkinsci/job-dsl-plugin/wiki/Testing-DSL-Scripts, if we create jobs that contain spaces in the job name the test fails because it can't write config.xml.  This seems to be because the path is being URL encoded (spaces replaced with %20).  If the DSL script replaces the spaces with underscores then the tests pass.

      Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslException'
      Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslException'
      at spock.lang.Specification.noExceptionThrown(Specification.java:118)
      at JobScriptsSpec.test script #file.name(JobScriptStep.groovy:25)
      Caused by: javaposse.jobdsl.dsl.DslException: java.io.IOException: Failed to persist config.xml
      at javaposse.jobdsl.plugin.JenkinsJobManagement.createNewItem(JenkinsJobManagement.java:569)
      at javaposse.jobdsl.plugin.JenkinsJobManagement.createOrUpdateConfig(JenkinsJobManagement.java:144)
      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.extractGeneratedJobs_closure4(AbstractDslScriptLoader.groovy:189)
      at groovy.lang.Closure.call(Closure.java:414)
      at groovy.lang.Closure.call(Closure.java:430)
      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.extractGeneratedJobs(AbstractDslScriptLoader.groovy:182)
      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.extractGeneratedItems(AbstractDslScriptLoader.groovy:169)
      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts_closure1(AbstractDslScriptLoader.groovy:62)
      at groovy.lang.Closure.call(Closure.java:414)
      at groovy.lang.Closure.call(Closure.java:430)
      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:81)
      at JobScriptsSpec.test script #file.name(JobScriptStep.groovy:22)
      Caused by: java.io.IOException: Failed to persist config.xml
      at hudson.model.ItemGroupMixIn.createProjectFromXML(ItemGroupMixIn.java:292)
      at jenkins.model.Jenkins.createProjectFromXML(Jenkins.java:3838)
      at javaposse.jobdsl.plugin.JenkinsJobManagement.createNewItem(JenkinsJobManagement.java:561)
      ... 12 more
      Caused by: javax.xml.transform.TransformerException: java.io.FileNotFoundException: /tmp/hudson8060308975604458205test/jobs/some-job-name%20-%20R2/config.xml (No such file or directory)
      at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:297)
      at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:330)
      at jenkins.util.xml.XMLUtils._transform(XMLUtils.java:212)
      at jenkins.util.xml.XMLUtils.safeTransform(XMLUtils.java:84)
      at hudson.model.ItemGroupMixIn.createProjectFromXML(ItemGroupMixIn.java:272)
      ... 14 more
      Caused by: java.io.FileNotFoundException: /tmp/hudson8060308975604458205test/jobs/some-job-name%20-%20R2/config.xml (No such file or directory)
      at java.io.FileOutputStream.open(FileOutputStream.java:270)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
      at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:287)
      ... 18 more

        Attachments

          Activity

          Hide
          gkrupa Gerard Krupa added a comment -

          Appears to be related to the Xalan class org.apache.xalan.transformer.TransformerIdentityImpl which is trying to convert file:/ URLs to local file names using a substring extraction instead of something like new File(new URI(...)).

          Show
          gkrupa Gerard Krupa added a comment - Appears to be related to the Xalan class org.apache.xalan.transformer.TransformerIdentityImpl which is trying to convert file:/ URLs to local file names using a substring extraction instead of something like new File(new URI(...)).
          Hide
          daspilker Daniel Spilker added a comment -

          First of all, try to avoid spaces in job names. Job names are used as file and directory name and in URL and spaces will cause problems. Use the job's display name to set a nice and human readable name. Jenkins will use the display name in the UI when it's set.

          Coming back to the issue. The problem is that some of the test dependencies (mainly jenkins-test-harness) add transitive dependencies to Xalan and Xerces to the test classpath. Without these dependencies the tests should run fine.

          You can exclude the dependencies from the classpath. See https://github.com/jenkinsci/job-dsl-plugin/pull/1055.

          IMHO jenkins-test-harness should be fixed to avoid these kind of dependencies since they alter the behavior of the subject to test.

          Show
          daspilker Daniel Spilker added a comment - First of all, try to avoid spaces in job names. Job names are used as file and directory name and in URL and spaces will cause problems. Use the job's display name to set a nice and human readable name. Jenkins will use the display name in the UI when it's set. Coming back to the issue. The problem is that some of the test dependencies (mainly jenkins-test-harness) add transitive dependencies to Xalan and Xerces to the test classpath. Without these dependencies the tests should run fine. You can exclude the dependencies from the classpath. See https://github.com/jenkinsci/job-dsl-plugin/pull/1055 . IMHO jenkins-test-harness should be fixed to avoid these kind of dependencies since they alter the behavior of the subject to test.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Daniel Spilker
          Path:
          docs/Home.md
          docs/Testing-DSL-Scripts.md
          http://jenkins-ci.org/commit/job-dsl-plugin/b3fe684d37ae95802247b6b17be775c0baf519a9
          Log:
          Merge pull request #1055 from daspilker/JENKINS-45512

          updated documentation to avoid undesired libraries on the test classpath

          Compare: https://github.com/jenkinsci/job-dsl-plugin/compare/655f9f1143bc...b3fe684d37ae

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Spilker Path: docs/Home.md docs/Testing-DSL-Scripts.md http://jenkins-ci.org/commit/job-dsl-plugin/b3fe684d37ae95802247b6b17be775c0baf519a9 Log: Merge pull request #1055 from daspilker/ JENKINS-45512 updated documentation to avoid undesired libraries on the test classpath Compare: https://github.com/jenkinsci/job-dsl-plugin/compare/655f9f1143bc...b3fe684d37ae

            People

            • Assignee:
              daspilker Daniel Spilker
              Reporter:
              gkrupa Gerard Krupa
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: