Jenkins 流水线语法进阶 07 循环语句 for while
for循环语句
// for
// 遍历0-9,打印
for (i=1; i<10; i++ ){
println(i)
}
// 循环5次
5.times {
println("hello")
}
// 遍历 0-4
5.times { i ->
println(i)
}
// 遍历List
def serverList = ["server-1", "server-2", "server-3"]
for ( i in serverList){
println(i)
}
// 使用each遍历map
def stus = ["zeyang":"177", "jenkins":"199"]
stus.each { k, v ->
println(k+"="+v)
}
// 使用for遍历map
for (k in stus.keySet()){
println(k+"="+stus[k])
}
while循环语句
// while 循环
String name = "jenkins"
while (name == "jenkins"){
println("true....")
name = "lisi"
}
目录 返回
首页