bash - Jenkins运行脚本文件
问题描述
我有一个运行脚本文件的 Jenkins 流水线。
我已经在 Jenkins 之外测试了脚本并且它运行完美,但是当我尝试将它作为管道的一部分运行时,我收到以下错误:
/maint/git-branches.sh: line 2: syntax error: unexpected "("
脚本是:
#!/bin/bash
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
for branch in "${branches[@]}"; do
echo "${branch##*/}"
done
我的管道阶段是:
stage ('Fetching Branches') {
steps {
script {
def branchcollection = sh (script: "sh maint/git-branches.sh", returnStdout: true).trim()
BRANCH = input message: 'Choose branch to pull from', ok: 'Ok', parameters: [choice(name: 'BRANCH', choices: "${branchCollection}", description: '')]
}
}
}
所有')'
支架都匹配,因此任何地方都没有松动的支架。
解决方案
The pipeline code is running git-branches.sh
explicitly with sh
. On some systems sh
is not Bash, and does not support Bash-specific features. In this case it looks like sh
does not support arrays. Try modifying the pipeline code to ... "bash maint/git-branches.sh"...
.
推荐阅读
- javascript - 如何在 react-native 项目中启用 jsconfig.json
- chef-infra - “install.sh:没有这样的文件或目录”执行刀单准备时
- javascript - 使用 Window.getSelection() 方法编辑 html 时出现问题 - Html 格式错误
- sql - 创建用于自动生成主键值的触发器时出现问题
- python - 从多索引数据框中删除最后一行
- linux - 在 docker 容器内为 i2c 运行 echo 命令时面临问题
- cmake - 自动将链接选项添加到共享库的依赖项
- python - 如何从中间左右交替打印Python链表中的元素?
- ggplot2 - 在ggplot中绘制极小的Y轴值
- c++ - 我不明白如何计算素数并且 modPow 函数在以下代码中工作