簡體   English   中英

如何將 Groovy 數組傳遞給 Jenkins 中的 Shell 腳本

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

我需要獲取我在 groovy 腳本中的數組並將其傳遞給 shell 腳本,以便在 Shell 腳本中進行進一步計算

我嘗試了多個,但我沒有將數組傳遞給 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
"""

嘗試以下選項之一。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM