【问题标题】:"./gradlew: Permission denied" when deploying a jhipster 5.1.0 project on Gitlab-CI在 Gitlab-CI 上部署 jhipster 5.1.0 项目时出现“./gradlew: Permission denied”
【发布时间】:2018-08-08 17:45:22
【问题描述】:

我使用的是 jhipster 5.1.0,我使用“jhipster ci-cd”来生成 .gitlab-ci.yml 文件。 我在我公司的私有 Ubuntu 18.04LTS 服务器上运行 Gitlab 和 Gitlab-CI。我将 Gitlab Runner 配置为使用 docker 执行构建。

我的.gitlab-ci.yml文件如下(我没怎么修改):

image: jhipster/jhipster:v5.1.0

cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
        - .gradle/wrapper
        - .gradle/caches
stages:
    - build

before_script:
    - export GRADLE_USER_HOME=`pwd`/.gradle
    - ./gradlew yarn_install -PnodeInstall --no-daemon

gradle-build:
    stage: build
    script:
        - ./gradlew compileJava -x check -PnodeInstall --no-daemon
        - ./gradlew test -PnodeInstall --no-daemon
        - ./gradlew yarn_test -PnodeInstall --no-daemon
        - ./gradlew bootJar -Pprod -x check -PnodeInstall --no-daemon
    artifacts:
        paths:
            - build/libs/*.jar
# Uncomment following to expire the artifacts after defined period, https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts-expire_in
#       expire_in: 90 day

这是 gitlab-ci 运行器的输出:

...
Successfully extracted cache
$ export GRADLE_USER_HOME=`pwd`/.gradle
$ ./gradlew compileJava -x check -PnodeInstall --no-daemon
/bin/bash: line 60: ./gradlew: Permission denied
ERROR: Job failed: exit code 1

由于问题似乎很明显,我尝试在“before_script”部分的“.gradlew”调用之前添加“-chmod +x gradlew”。我认为这将是一个好主意,因为它是在 5.1.0 之前由“jhipster ci-cd”命令生成的,但现在不是了。没有成功:Gitlab-CI 输出变成如下:

...
Successfully extracted cache
$ export GRADLE_USER_HOME=`pwd`/.gradle
$ chmod +x gradlew
chmod: changing permissions of 'gradlew': Operation not permitted
ERROR: Job failed: exit code 1

所以我尝试在 .gitlab-ci.yml 文件中切换到 docker 映像“openjdk:8”而不是“jhipster/jhipster:v5.1.0”。更好的是,gradle 运行“yarn install”命令,但它会在某个时候停止,因为该容器不包含“libpng-dev”(这是最近添加到 jhipster 容器中的,运气不好!):

...
[5/5] Building fresh packages...
error An unexpected error occurred: 
"/builds/epigone/exportCCN/node_modules/pngquant-bin: Command failed.
Exit code: 1
Command: sh
Arguments: -c node lib/install.js
Directory: /builds/epigone/exportCCN/node_modules/pngquant-bin
Output:
⚠ The `/builds/epigone/exportCCN/node_modules/pngquant-bin/vendor/pngquant` 
binary doesn't seem to work correctly
   ⚠ pngquant pre-build test failed
   ℹ compiling from source
   ✔ pngquant pre-build test passed successfully
   ✖ Error: pngquant failed to build, make sure that libpng-dev is installed
      at Promise.all.then.arr (/builds/epigone/exportCCN/node_modules/pngquant-bin/node_modules/bin-build/node_modules/execa/index.js:231:11)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)".
info If you think this is a bug, please open a bug report with the information provided in "/builds/epigone/exportCCN/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
:yarn_install FAILED

【问题讨论】:

  • 哪个用户帐户拥有gradlew 脚​​本,以及它所在的目录?在这里适当地投入一些资源来弄清楚 为什么 chmod +x 失败。
  • 顺便说一句,sh -c node lib/install.js 有很多问题。 sh -c 'node lib/install.js' 并没有那么明显,但是您的调试输出并没有让我们知道您的代码实际上正在尝试运行哪些代码。
  • 另外,与您的问题无关,但$(pwd) 分叉了一个子shell,因此比$PWD 慢得多;尝试改掉使用前者(或其基于反引号的等效项)的习惯。
  • 您可以尝试使用正确的权限将 gradlew 提交给 git
  • 我无法修改 jhipster 容器;我可能应该在他们的论坛上更直接地问他们。他们把它放在 Dockerhub 上:hub.docker.com/r/jhipster/jhipster,Dockerfile 在这里:github.com/jhipster/generator-jhipster/blob/v5.1.0/Dockerfile。通过查看 dockerfile,您可能比我更了解chmod +x 失败的原因。无论如何,他们从最新版本的 .gitlab-ci.yml 文件中删除了该行,因此让它工作可能不是一个好主意:./gradlew 命令应该立即运行。

标签: docker jhipster gitlab-ci


【解决方案1】:

你需要修改你的 git repo 的权限。 运行:

git update-index --chmod=+x gradlew

然后提交并推送。

【讨论】:

  • 非常感谢,成功了!!!没想到这么久有答案!
  • 没问题,很高兴它成功了。我遇到了同样的问题,并试图解决它。
  • 你拯救了我的一天。即使我的文件在 Windows 的 Git Bast 中具有执行权限,但 Git 服务器中的文件没有权限。所以我不得不使用git update-index --chmod=+x gradlew,它起作用了。
猜你喜欢
  • 2019-08-16
  • 1970-01-01
  • 2020-02-05
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-21
相关资源
最近更新 更多