9

I am using jhipster 5.1.0, I used "jhipster ci-cd" in order to generate the .gitlab-ci.yml file. I am running Gitlab and Gitlab-CI on a private Ubuntu 18.04LTS server in my company. I configured the Gitlab Runner to execute the builds with docker.

My .gitlab-ci.yml file is as follows (I did not modify it much):

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

Here is the output of the gitlab-ci runner:

...
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

As the problem seems obvious, I tried to add " - chmod +x gradlew", before the ".gradlew" call in the "before_script" section. I thought it would be a good idea, because it was generated by the "jhipster ci-cd" command before 5.1.0, but not anymore. No success: Gitlab-CI output became as follows:

...
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

So I tried to switch to the docker image "openjdk:8" instead of "jhipster/jhipster:v5.1.0", in the .gitlab-ci.yml file. Much better, gradle runs the "yarn install" command, but it stops at some point, because that container does not contain "libpng-dev" (which was added recently into the jhipster container, no luck !):

...
[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
PositronBeam
  • 136
  • 1
  • 6
  • Which user account owns the `gradlew` script, and the directory it's in? It's appropriate here to put some resources into figuring out *why* the `chmod +x` failed. – Charles Duffy Aug 08 '18 at 18:05
  • BTW, `sh -c node lib/install.js` is quite buggy. `sh -c 'node lib/install.js'` isn't as obviously so, but your debug output doesn't let us know which of those your code is actually trying to run. – Charles Duffy Aug 08 '18 at 18:07
  • As another aside, not related to your problem, but `$(pwd)` forks off a subshell, and is thus much slower than `$PWD`; try to get out of the habit of using the former (or its backtick-based equivalent). – Charles Duffy Aug 08 '18 at 18:08
  • You could try committing gradlew to git with the correct permissions – Jon Ruddell Aug 08 '18 at 18:41
  • I can't modify the jhipster container; I should probably ask them more directly on their forum. They put it on Dockerhub: https://hub.docker.com/r/jhipster/jhipster/ , and the Dockerfile is here: https://github.com/jhipster/generator-jhipster/blob/v5.1.0/Dockerfile . You are probably better than me to see why the `chmod +x` failed, by looking at the dockerfile. Anyway, they removed that line from the latest versions of their .gitlab-ci.yml file, so it is probably not a good idea to make it work: the `./gradlew` command should run out of the box. – PositronBeam Aug 09 '18 at 07:38
  • Regarding the `sh -c node lib/install.js` problem: this command is run by a dependency somewhere deep into the node modules installed by the `yarn install` command, and I can't modify it, because these packages are automatically downloaded by yarn. Here, the problem is the openjdk:8 container not having `libpng-dev` installed. I tried to add a `apt-get install libpng-dev` command in the .gitlab-ci.yml file, but Gitlab-CI outputed the following error: `E: Unable to locate package libpng-dev`, probably because this command can't see the apt-get servers from inside the container. – PositronBeam Aug 09 '18 at 07:49

1 Answers1

21

You need to modify the permissions on your git repo. Run:

git update-index --chmod=+x gradlew

then commit and push.

Megadec
  • 466
  • 10
  • 25
  • Thank you very much, it worked !!! I didn't expect any answer after such a long time ! – PositronBeam Feb 06 '19 at 16:31
  • No Problem at all, glad it worked. I came across the same issue and was pulling my hair out over it trying to fix it. – Megadec Feb 18 '19 at 09:19
  • 1
    You saved my day. Even though my file had execution permission in Git Bast in Windows, the file in Git server didn't have the permission. so I had to use `git update-index --chmod=+x gradlew` and it worked. – mazend Dec 15 '20 at 12:46