我在我的腳本中使用了 for-loop 來逐一運行,這在 def 資料中提到它正在執行,它在 def 資料中給出了多少個值,但在 def 資料中,這個詞沒有選擇,也沒有應用于句子。
幫助我解決這個問題,幫助我解決原始問題
例子
Def data = [ "apple","orange" ]
Stage(create sentence){
Steps{
Script {
For (x in data){
Sh 'the fruit name is ${x}
}
}
}
}
例外輸出
水果名稱是蘋果
水果名稱是橙色
但我的輸出就像
水果名稱是
水果名稱是
uj5u.com熱心網友回復:
要在這種情況下使用不需要的回圈,您可以簡單地在您擁有的串列中進行迭代。
僅迭代值:
data.each{
println it
}
或者
data.each {val->
println(val)
}
用索引迭代值:
data.eachWithIndex{it,index->
println "value " it " at index " index
}
所以,最終的管道看起來像這樣。
def data = [ "apple","orange" ]
pipeline {
agent any
stages
{
stage('create sentence')
{
steps
{
script{
data.each {val->
println("the fruit name is " val)
}
}
}
}
}
}
uj5u.com熱心網友回復:
如果要在sh塊中插入變數,請使用雙引號將其括起來。
Sh "the fruit name is ${x}"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/526267.html
標籤:詹金斯声明性的
上一篇:添加列Heroku資料庫
