Kucharsky
Kucharsky

Reputation: 263

Creating folders in Jenkins with Groovy

I have a problem with understanding job-dsl-plugin. I would like to create folders in my jenkins workspace but I don't know how to connect groovy script (and Object Oriented Programming) with dsl plugin.

class JenkinsDSL {
    def addFolder(def name) {
        println(name)
        //---GroovyDSL---
        folder(name) {
            displayName(name)
            description("${name} for project")
        }
        //---------------    
    }
}

def job = new JenkinsDSL()

job.addFolder("folder1")
job.addFolder("folder2")

Above script return the error:

javaposse.jobdsl.dsl.DslScriptException: (script, line 5) No signature of method: JenkinsDSL.folder() is applicable for argument types: (java.lang.String, JenkinsDSL$_addFolder_closure1) values: [folder1, JenkinsDSL$_addFolder_closure1@3fac6b47]

In configuration of Freestyle Project in Jenkins I tried to set the build step to groovy script and Process Job DSLs but I'm not sure which should be correct.

Upvotes: 0

Views: 2039

Answers (1)

V. Silverman
V. Silverman

Reputation: 21

It looks your task is to create a folder in a workspace using a freestyle project. Do the following: - name your freestyle project by the name of the folder, you would like to create. - in the build step execute any valid shell command. After you run the job - the folder with the the name of the project will be created in the workspace.

Upvotes: 2

Related Questions