[英]Jenkins Pipeline pass String array to function
我使用 Jenkins 管道,我想將字符串數組傳遞給本地 function; 我嘗試使用 Strinf 是可以的,但不是使用 String 數組。
在管道中::
stage('package') {
steps {
executeModuleScripts(["module1", "module2"])
}
}
在管道末端:
void executeModuleScripts(allModules) {
allModules.each { module ->
String gitFolder = "${module}"
script {
stage(module) {
bat 'xcopy "' + gitFolder + '/foo/*" "temp/PUB/foo" /C /S /I /F /H'
}
}
}
}
我有這個錯誤:
groovy.lang.MissingPropertyException: No such property: operation for class: groovy.lang.Binding
它必須是這樣的:
腳本流水線
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'
}
}
}
}
聲明式管道
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'])
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.