Provide an example for importing

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      We've been using the fantascic Job DSL plugin and its tests described at https://github.com/jenkinsci/job-dsl-plugin/wiki/Testing-DSL-Scripts for testing the scripts.

      However when we tried to add local imports to the groovy files (in the same directory structure as the job specifications, just one folder down, so for example in common/Jobs.groovy), while the plugin itself handles that nicely, I couldn't get that working in the test suite.

      I get the error:

      JobScriptsSpec > test script facebook.groovy STANDARD_OUT
          Processing provided DSL scriptJobScriptsSpec > test script facebook.groovy FAILED
          Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslScriptException'
              at spock.lang.Specification.noExceptionThrown(Specification.java:118)
              at JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:28)        Caused by:
              javaposse.jobdsl.dsl.DslScriptException: (script, line 34) No such property: Jobs for class: script
                  at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:114)
                  at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts_closure1(AbstractDslScriptLoader.groovy:61)
                  at groovy.lang.Closure.call(Closure.java:405)
                  at groovy.lang.Closure.call(Closure.java:421)
                  at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
                  at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:87)
                  at JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:24)            Caused by:
                  groovy.lang.MissingPropertyException: No such property: Jobs for class: script
                      at script.run(script:34)
                      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:138)
                      at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:108)
                      ... 6 more
      

      Could you please add an example on how to do imports in Job DSL files and test them?

            Assignee:
            Jamie Tanna
            Reporter:
            Attila Nagy
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: