Test DSL scripts which import packages

78 views
Skip to first unread message

Rolf Offermanns

unread,
Jul 6, 2018, 3:36:22 AM7/6/18
to job-dsl-plugin
Hi All,

on the Wiki page "Jenkins Job DSL Architecture" I found this section:

The GroovyScriptEngine is used to execute the script. It's been provided with a workspace handler, so that will look for classes in the workspace, meaning that if you create a mypackage/MyClass.groovy file, it'll use it if you do 'import mypackage.MyClass'.

And that is what I did to keep helper functions in a separate package. The directory structure looks like this:

job-dsl (dir)
     +-- mainJob.groovy
     +-- utilities (dir)
                +-- MyUtilities.groovy

It works fine when I run it in Jenkins but when I try to follow the instructions on the "Testing DSL Scripts" wiki page, the test fails because it cannot resolve the utilities.MyUtilities class.

I am not familiar with gradle and spock. Can anybody give me a hint what I need to do to get this working?

Thanks a lot,
Rolf

Attila Nagy

unread,
Jul 20, 2021, 7:56:27 AM7/20/21
to job-dsl-plugin
Hi,


The file structure should be:
.
├── src
│   ├── jobs                # DSL script files
│   ├── main
│   │   ├── groovy          # support classes
│   │   └── resources
│   │       └── idea.gdsl   # IDE support for IDEA
│   ├── scripts             # scripts to use with "readFileFromWorkspace"
│   └── test
│       └── groovy          # specs
└── build.gradle            # build file


So you should put utilities/MyUtilities.groovy into src/main/groovy/utilities/MyUtilities.groovy
Reply all
Reply to author
Forward
0 new messages