我有下面的共享库,它在Jenkins管道中使用。在遍历列表时,我希望得到以下输出
**firstDestination
secondDestination**
相反,我得到了
**[firstDestination,
secondDestination]**
我不明白为什么会这样。我的错误在哪里?
List<String> pushDestination = new ArrayList()
String suffix = ''
if (config.tagSuffix) {
suffix = "-$config.tagSuffix"
}
if (config.imageTag) {
List tagList = ParameterUtils.convertParameterToList(this, config.imageTag)
tagList.each { tag ->
String fullTag = "$tag$suffix"
fullTag = fullTag.replace('{commitId}', commitId)
pushDestination.add("firstDestination")
}
}
if (config.get('createCommitTag', false).toBoolean()) {
pushDestination.add("secondDestionation")
}
container('buildah') {
sh """
for currentDestination in ${pushDestination}; do
echo "currentDestination: \$currentDestination"
done
"""
}
}
1条答案
按热度按时间insrf1ej1#
从你的shell代码中,你有:
但是
${pushDestination}
将被渲染为字符串[ firstDestination, secondDestination ]
,但是bash需要不同的数组定义语法(即(a b c d)
),所以你想渲染如下: