gitlab ci shell script permission denied

gitlab项目做自动化部署,在.gitlab-ci.yml中配置了任务,如下

stages:
  - test
  - build

project-test:
  stage: test
  script:
    - mvn test
  tags:
    - maven-shell

如果提示找不到mvn命令

Running with gitlab-ci-multi-runner 9.5.1 (96b34cc)
  on maven-shell (3d23ab5f)
Using Shell executor...
Running on iZuf6cnvpgp38ql2ipgcbbZ...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/3d23ab5f/0/fanxl12/docker-test'...
Checking out a1c96ac4 as master...
Skipping Git submodules setup
$ source /etc/profile
$ mvn test
bash: line 66: mvn: command not found
ERROR: Job failed: exit status 1

或者提示没有权限

Running with gitlab-ci-multi-runner 9.5.1 (96b34cc)
  on maven-shell (3d23ab5f)
Using Shell executor...
Running on iZuf6cnvpgp38ql2ipgcbbZ...
Fetching changes...
HEAD is now at a1c96ac Update .gitlab-ci.yml
Checking out 7bcd83e9 as master...
Skipping Git submodules setup
$ $M2_HOME/bin/mvn test
bash: line 64: /root/developer/apache-maven-3.6.0/bin/mvn: Permission denied
ERROR: Job failed: exit status 1

原因是自己maven安装在自己创建的目录下,安装路径有问题

/root/developer/maven-3.6.0

我把安装移到

/usr/local/maven-3.6.0

mvn test命令就正常执行了

猜你喜欢

转载自blog.csdn.net/fanxl10/article/details/84643537