简体   繁体   English

如何将 Groovy 数组传递给 Jenkins 中的 Shell 脚本

[英]How To Pass a Groovy Array to Shell Script in Jenkins

I need to get the array that I have in my groovy Script and pass it shell Script for further Calculation in the Shell Script我需要获取我在 groovy 脚本中的数组并将其传递给 shell 脚本,以便在 Shell 脚本中进行进一步计算

I have tried multiple was but I am not getting the array passed to Shell Script.我尝试了多个,但我没有将数组传递给 Shell 脚本。

templates = ["Temp1","Temp2","Temp3"]
templateCount = templates.size()
sh """
  count = ${templateCount} 
  temp = ${templates}
  for (( i=0; i < count; i++ ))
  do
    echo "Template Name = " ${temp[i]}
   done
"""

Try one of the following options.尝试以下选项之一。

script {
    def templates = ["Temp1","Temp2","Temp3"]
    sh """
        for v in ${templates.join(' ')}
        do
            echo \$v
        done
    """

    // Option 2
    for(tmp in templates) {
        sh "echo ${tmp}"
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将值从一个 Shell 块传递到另一个 Shell 块或将该值分配给 GroovyADF35AB22E54ACEE5ADAD3 中 GroovyADF35AB22E54ACEE4C0 中的变量 - How to Pass Value from One Shell Block to Another Shell Block or assign that value to the Variable of the Groovy Script in Jenkins 如何将 groovy 变量传递给 Jenkinsfile 中的 shell 脚本? - How to pass groovy variable to shell script in Jenkinsfile? 如何在 Jenkins 管道脚本中使用 shell 脚本变量作为 groovy 变量 - How to use shell script variable as groovy variable in Jenkins pipeline script 如何在 shell 脚本中访问 jenkins groovy 变量的值以进行循环 - How to access value of a jenkins groovy variable in shell script for loop 如何访问 jenkins 管道中 shell 脚本中的 groovy 变量? - How to access a groovy variable in shell script in jenkins pipeline? 将 groovy 变量传递给 shell 脚本 - Pass groovy variable to shell script 何时在Jenkins中使用Groovy和Shell脚本? - When to use Groovy versus a shell script in Jenkins? Jenkins Groovy 脚本来执行 shell 命令 - Jenkins Groovy script to execute shell commands 如何将数组作为参数传递给 shell 脚本并在 shell 脚本中获取该数组 - How to pass array as an argument to shell script and fetch that array in shell script 如何使用 Jenkins 主动选择参数 groovy 脚本在远程服务器中执行 shell 脚本? - How to execute shell script in remote server using Jenkins Active choice parameter groovy script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM