Unversioned files due to “?” folder automatically

2019-09-21 07:12发布

问题:

I am configuring Continuous Delivery with gradle using the gradle release plugin. This was working quite well using Travis CI. I am testing the same CD pipeline with Jenkins pipeline compiling everything in a docker container (gradle:4.7.0-jdk8). But I am receiving this error:

Execution failed for task ':t_gradle-release-example_release:checkCommitNeeded'.
> You have unversioned files:
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ?? ?/
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Of course there is no such directory in the repo and it appears when compiling the repository. The repo is available in GitHub. As a workaround I removed the "?" folder (I can also include it in the .gitignore), but I need to know why this is happening in order to avoid the same issue in future pipelines.

UPDATE: It is happening to me also in GitLab. Any clue?

UPDATE 2: Inside the "?" folder there are three folders ".sonar",".gradle",".m2". Some volumes are shared between containers to cache dependencies. Could it be the reason?

回答1:

Finally I found the issue thanks to this post. Basically Jenkins runs the docker container with the user 1002 and there is no user defined. The variable user.home is not set and gradle, maven or sonar cannot properly locate where to put the dependencies. If user.home is not found then it (or docker or the OS) creates a "?" folder and put the .gradle, .m2 or .sonar inside to download them. The solution to avoid this weird issue is to configure user.home in the JAVA_OPTIONS including the following environment variable:

withEnv(['_JAVA_OPTIONS=-Duser.home=/var/gradle'])

and create a volume for it to cache the dependencies:

docker.image("gradle:4.7.0-jdk8").inside("-v /home/jenkins:/var/gradle")