Gitlab Shell脚本权限被拒绝。

12

我正在使用Gitlab CICD运行一个简单的shell脚本,但是出现了Permission denied(权限被拒绝)错误,请给予建议。

当我执行chmod +x test.sh时,它会提示“操作不允许”(operation not permitted)。

stages:
  - build 

build: 
  stage: build 
  script: 
    - ls
    - ./test.sh

Shell test.sh

echo Hi

错误:

在这里输入图片描述


请不要发布代码、错误信息或其他文本数据的图像。 - tripleee
4个回答

10

不要仅仅在本地运行chmod,最好运行git update-index --chmod=+x path/to/file。这将向Git中的文件添加可执行标志,应确保脚本可以在GitLab pipeline中执行。

另请参阅此问题


3

2

第23行告诉我们它正尝试使用/bin/bash执行脚本,但是它没有权限。

尝试通过运行以下命令为文件赋予执行权限:

sudo chmod 755 test.sh

2

你需要执行以下操作之一:

1- 运行 bash ./test.sh

或者

2- 在 test.sh 的开头添加一行 #!/bin/bash,这样它就知道在 Bash 中运行它了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接