运行 bash 脚本的詹金斯管道中的权限被拒绝

问题描述 投票:0回答:2

团队,尝试通过 jenkins 管道运行脚本时权限被拒绝,任何线索可能是什么原因导致 shell 脚本没有被执行?我尝试了所有可以的组合..仍在寻找..我在管道本身中给出了所有 777 权限。我遵循了this,但没有运气。

/home/jenkins/agent/workspace/team/code-coverage-WIP@tmp/durable-29cd82d6/script.sh: 4: //: 权限被拒绝

  steps {
    preBuild(bazel_init)
    container('main') {
      sh '''
        pwd
        ls -ltr
        ls -ltr scripts/test-report.sh
        chmod 777 scripts/test-report.sh
        ls -ltr scripts/test-report.sh
        BAZEL_OPTS="--config=ci --config=remote_cache_ci"
        scripts/test-report.sh
      '''.stripIndent()

输出

+ ls -ltr scripts/test-report.sh
-rwxr-xr-x 1 jenkins jenkins 238 Dec 9 06:18 scripts/test-report.sh

+ chmod 777 scripts/test-report.sh
+ ls -ltr scripts/test-report.sh
-rwxrwxrwx 1 jenkins jenkins 238 Dec 9 06:18 scripts/test-report.sh

+ BAZEL_OPTS=--config=ci --config=remote_cache_ci
+ scripts/test-report.sh

/home/jenkins/agent/workspace/team/code-coverage-WIP@tmp/durable-29cd82d6/script.sh: 4: //: Permission denied

剧本是

#!/bin/bash
set -e
which bazel
bazelbin=$(bazel info bazel-bin)
target="//src/cmd/gocoverage"
cmd="${bazelbin}/src/cmd/gocoverage/gocoverage_/gocoverage"
bazel build $target
$cmd -goprefix=go.corp.nvidia.com/maglev ${GOCOVERAGE_OPTS} $@

bash jenkins-pipeline containers sh
2个回答
0
投票

我必须从脚本中删除

#!/bin/bash
,然后在管道中使用如下所示

                              sh '''
                                chmod 777 -R scripts
                                BAZEL_OPTS="--config=ci --config=remote_cache_ci"
                                bash scripts/test-report.sh
                              '''.stripIndent()

0
投票

AhmFM 的最后一个答案对我有用!谢谢你。

© www.soinside.com 2019 - 2024. All rights reserved.