Run groovy script system in jenkins from DSL work plugin

Preparation lack of signatures for the method readFileFromWorkspace () in the job seed Jenkins (when attempting to perform main.groovy . Dsl plug of job main.groovy causes static class method PrepareBuildPublish.groovy to create assignments):

ERROR: (PrepareBuildPublish.groovy, line 43) No method signature: javaposse.jobdsl.dsl.helpers.step.StepContext.readFileFromWorkspace () applicable for argument types: (java.lang.String) values: [WorkspaceLocker.groovy]

Here is the source code for main.groovy

import models.*
import templates.*

import hudson.FilePath
import org.yaml.snakeyaml.Yaml

createJobs()

void createJobs() {
    def yaml = new Yaml()

    // Build a list of all config files ending in .yml
    def cwd = hudson.model.Executor.currentExecutor().getCurrentWorkspace().absolutize()
    def configFiles = new FilePath(cwd, 'ci-repos').list('*.yml')

    // create jobs for each config file
    configFiles.each { file ->
        def projectConfig = yaml.loadAs(file.readToString(), ProjectConfig.class)
        def project = projectConfig.project.replaceAll(' ', '-')

        PrepareBuildPublish.create(job("${project}-Prepare-Build-Publish"), projectConfig)
    }
}

      

Here is the source code for PrepareBuildPublish.groovy

    package templates

    class PrepareBuildPublish {
        static void create(job, config) {
            job.with {         

                logRotator {
                    daysToKeep(7)
                    numToKeep(15)
                }

                steps {
                    systemGroovyCommand(readFileFromWorkspace('WorkspaceLocker.groovy')){
                        binding('repo','${config.repo}')
                        classpath()
                    }
                }
            }
    }
}

      

Why is the readFileFromWorkspace () method not found? If I use the same step block configuration directly in the DSL Workflow Role Plugin DSL then it works - then it must be something groovy related and how I am calling this method.

+3


source to share





All Articles