1

I use Jenkins pipeline and I want pass String array to local function; i try with a Strinf is ok but not with a String array.

in pipeline::

stage('package') {
    steps {
        executeModuleScripts(["module1", "module2"])
    }
}

at the end of pipeline:

void executeModuleScripts(allModules) {

    allModules.each { module ->
    
        String gitFolder = "${module}"
          
        script {
            stage(module) {
                bat 'xcopy "' + gitFolder + '/foo/*" "temp/PUB/foo" /C /S /I /F /H'
            }
        }

    }   
}

I have this error:

groovy.lang.MissingPropertyException: No such property: operation for class: groovy.lang.Binding

1 Answer 1

2

It has to be like :

Scripted Pipeline

node {
    stage('package') {
        executeModuleScripts(['01','02'])
    }
}
void executeModuleScripts(allModules) {
    allModules.each { module ->
        script {
            stage(module) {
                // sh "cp -R ${module}/foo/* temp/PUB/foo"
                bat 'xcopy "' + module + '/foo/*" "temp/PUB/foo" /C /S /I /F /H'
            }
        }

    }   
}

Declarative Pipeline

void executeModuleScripts(allModules) {
    allModules.each { module ->
        script {
            stage(module) {
                // sh "cp -R ${module}/foo/* temp/PUB/foo"
                bat 'xcopy "' + module + '/foo/*" "temp/PUB/foo" /C /S /I /F /H'
            }
        }

    }   
}

pipeline {
    agent any;
    stages {
        stage('package') {
            steps {
                executeModuleScripts(['A','B'])
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.