首页 > 解决方案 > Jenkins运行脚本文件

问题描述

我有一个运行脚本文件的 Jenkins 流水线。

我已经在 J​​enkins 之外测试了脚本并且它运行完美,但是当我尝试将它作为管道的一部分运行时,我收到以下错误:

/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: '')]
            }
          }
        }

所有')'支架都匹配,因此任何地方都没有松动的支架。

标签: bashjenkins

解决方案


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"....


推荐阅读