0

I have a groovy script to create the folders for my Jenkins server. The folders plugin is installed and working. I also installed the Job DSL plugin and created the Seed job. There are 2 options for supplying the groovy DSL code. 1. Use the provided DSL script or 2. Look on the filesystem.

If I use option 1 and supply this script it works perfectly and I see the folders:

def folders = '''
Active Folder
Active Folder/DqCpi
Active Folder/DqCtlRent
Active Folder/DqFileBox
'''

def folderList = folders.tokenize('\n')

for (folderName in folderList) {
    folder(folderName)
}

So far so good.

I save this code into Folders.groovy inside the seed job's workspace folder then try option 2

This fails and the error message in the console is:

Processing DSL script Folders.groovy
ERROR: (Folders.groovy, line 1) No signature of method: Folders.?def() is applicable for argument types: (java.lang.String) values: [
Active Folder
Active Folder/DqCpi
Active Folder/DqCtlRent
Active Folder/DqFileBox
]
Possible solutions: grep(), folder(java.lang.String), job(java.lang.String), queue(java.lang.String), use([Ljava.lang.Object;), grep(java.lang.Object)
Finished: FAILURE

The file Folders.groovy is saved in UTF8 format.

Why does in the inline version work and the file version fail?

Matthew MacFarland
  • 2,413
  • 3
  • 26
  • 34
  • I can not reproduce your problem. Which version of Jenkins and the Job DSL plugin are you using? Is Folders.groovy the only script that you run? – daspilker Nov 30 '15 at 08:32
  • @daspilker - My Jenkins version is 1.617 and the Job DSL plugin is version 1.40. I am running only Folders.groovy in this case. – Matthew MacFarland Nov 30 '15 at 13:51
  • @daspilker - I thought maybe the Groovy version was out of date since Jenkins lists Groovy 1.8.9 in the About Jekins page and I think Groovy is available in a higher version. The latest version of Jenkins seems to use the same Groovy version 1.8.9. I'll update Jenkins anyway in case there is some incompatibility between my Jenkins version and the plugin. – Matthew MacFarland Nov 30 '15 at 14:01

1 Answers1

0

It appears that this is related to the encoding of the script file. My text editor Notepad++ saved the file Folders.groovy in UTF8.

I then noticed on the Jenkins system properties page the following setting sun.io.unicode.encoding UnicodeLittle

I opened the file Folders.groovy and changed the encoding from UTF8 to UTF8 without BOM. After this change the script works perfectly.

UPDATE I updated to the latest version of Jenkins and tried saving the Groovy script in UTF8 but it still fails. I have tried ANSI and UTF8 w/o BOM which both work fine so we'll just have to get used to saving our scripts with non-default encoding.

Matthew MacFarland
  • 2,413
  • 3
  • 26
  • 34
  • I think the non-default format came from Visual Studio 2013. I created a new empty text file in Windows, added it to the source control folder, opened it with the default Visual Studio text editor, and then saved it. That is the version had the non-standard format (UTF8 with BOM). Both Notepad++ and Sublime defaulted to UTF8 without BOM which is the encoding that works. – Matthew MacFarland Nov 30 '15 at 18:46