Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

groovy - Jenkins Pipeline pass String array to function

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
question from:https://stackoverflow.com/questions/66066616/jenkins-pipeline-pass-string-array-to-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'])
            }
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...