Jenkinsfile -合并变量以调用第三个变量

xhv8bpkk  于 2023-03-17  发布在  Jenkins
关注(0)|答案(1)|浏览(155)

我想知道下面的场景是否可行。我尝试在管道中放置一些逻辑来合并两个变量以调用第三个。下面我定义了食物,并在第一个循环中添加了'_juice'。此时我想迭代数组'chips_juice',但它只返回单个字符。
任何帮助都将不胜感激

def food = ['chips']
def chips_juice = ['lovely-meal']

food.each { grub ->
  env.meal = grub + '_juice'
  meal.each {dinner ->
    println dinner
  }
}

结果

[Pipeline] echo
c
[Pipeline] echo
h
[Pipeline] echo
i
[Pipeline] echo
p
[Pipeline] echo
s
[Pipeline] echo
_
[Pipeline] echo
j
[Pipeline] echo
u
[Pipeline] echo
i
[Pipeline] echo
c
[Pipeline] echo
e
[Pipeline] node

我尝试过以不同的格式定义meal变量,但是这要么会停止管道,要么会返回相同的结果。

ecbunoof

ecbunoof1#

你不可能用你现在尝试的方法来达到这个目标,但是你可以做一些类似下面的事情。

food = ['chips']
chips_juice = ['lovely-meal']

food.each { grub ->
  def meal = grub + '_juice'
  def newList = this.getBinding().getVariable(meal);

  newList.each {dinner ->
    println dinner
  }
}

相关问题