I’m fairly new to Gradle but the project I’m working on is quite large.
I have an issue where Jenkins is running a groovy script with the gradle plugin. The project dir is correct when jobs run through the master node /opt/jenkins/workspace/, but on another node the current directory is /home/jenkins/.gradle/daemon/6.5
Looking further into this the user.dir variable is the issue, but I’m not sure why this would differ
What could cause this difference? I’m not 100% sure where I should look
A build should never depend on the current working directory.
Gradle tries to set the current working directory of an existing daemon to the cwd of the calling process, but this sometimes does not work properly (when calling through tooling api) or even is not possible properly anymore with Java 11 and even in earlier Java versions only partly worked.
This will eventually also be removed completely in one of the next major versions.
For the whole story, read Consider not changing the current working dir for builds running in a daemon but always use Gradle user home as working dir · Issue #16748 · gradle/gradle · GitHub
But in short summarized, any build logic depending on the current working directory, for example by using
new File(...) with a relative path instead of properly using
project.layout.projectDirectory.file(...) and so on can be considered broken and flaky and should be fixed.