2

Using the following Jenkins Groovy script, observing Could not create parent directory for lock file /home/ubuntu/.gradle/.../gradle-6.7.1-all.zip.lck error

stage('Run build'){
     steps {
                sh "./gradlew --update-locks assembleDebug"
                sh "./gradlew -DinputParam=${PARAM} --info clean test"
            }
}

This build was working in the past, but now causing this lock file issue. Reading this post, added the --update-locks assembleDebug step, still the issue is not resolved.

Please advice what is the best approach to have a clean gradle build and to fix this runtime issue.

Tulip
  • 51
  • 4

1 Answers1

2

Rule of thumb: one project = one workspace = one gradle user home

For each project that has a Jenkinsfile, it builds in its own workspace, and run Gradle with a GRADLE_USER_HOME local to that workspace. That way there is no concurrency issue, but each build has it's own cache for dependencies and there is no way to mutualize that.

There are files that do not support concurrent access in the gradle user home and that cannot be shared across several runners.

This is inefficient regarding disk use, but it should work:

stage('prepare') {
    env.GRADLE_USER_HOME = "$WORKSPACE/.gradle"
}
stage('Run build') {
    // ...
}
Tulip
  • 51
  • 4