I have a Jenkins running as a standalone server, i.e. it is not running as a Docker container. For building my application with Gradle I'm using a Docker image as shown below.
stages {
stage('Compile') {
steps {
script {
docker.image("gradle:6.2.2-jdk8").inside("-v ${HOME}/.gradle:/gradle/.gradle") {
sh './gradlew clean vaadinPrepareNode build -Pvaadin.productionMode'
sh "mkdir -p ${GRADLE_DEPENDENCY_PATH} && (cd build/dependency; jar -xf ../libs/*.jar)"
}
}
}
}
}
My problem is the following: There is a Gradle task which tries to access the directory /.npm
. However the jenkins
user launching the Docker container (uid=1002(jenkins) gid=1002(jenkins)
) seems not to have the permissions to do that. Therefore the task fails.
When changing the pipeline statement to docker.image("gradle:6.2.2-jdk8").inside("-u root -v ${HOME}/.gradle:/gradle
the build finishes successfully but then I have folders owned by root
in the workspace which cannot be deleted by Jenkins.