简体   繁体   English

Jenkins运行脚本文件

[英]Jenkins running script file

I have a Jenkins Pipeline that runs a script file. 我有一个运行脚本文件的Jenkins Pipeline。

I have tested the script outside of Jenkins and it runs perfectly but when I try to run it as part of the pipeline I get the following error: 我已经在Jenkins之外测试了脚本,并且脚本运行良好,但是当我尝试将其作为管道的一部分运行时,出现以下错误:

/maint/git-branches.sh: line 2: syntax error: unexpected "("

The script is: 脚本是:

#!/bin/bash
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
for branch in "${branches[@]}"; do
   echo "${branch##*/}"
done

And my pipeline stage is: 我的管道阶段是:

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

All the ')' brackets match up so there's no loose ones anywhere. 所有的')'括号都匹配,因此任何地方都没有松散的括号。

The pipeline code is running git-branches.sh explicitly with sh . 管道代码使用sh显式运行git-branches.sh On some systems sh is not Bash, and does not support Bash-specific features. 在某些系统上, sh不是Bash,并且不支持Bash特定的功能。 In this case it looks like sh does not support arrays. 在这种情况下, sh似乎不支持数组。 Try modifying the pipeline code to ... "bash maint/git-branches.sh"... . 尝试将管道代码修改为... "bash maint/git-branches.sh"...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM