0

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.

Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
  • What directories are mentioned by you which you cannot delete? – Chris Mar 22 '20 at 17:39
  • Just found out that it doesn't seem to be a problem. The build works fine and so does the cleanup by Jenkins. I was just wondering if it's recommended to run the container as `root`? – Robert Strauch Mar 22 '20 at 19:28
  • https://medium.com/@mccode/processes-in-containers-should-not-run-as-root-2feae3f0df3b – Chris Mar 22 '20 at 20:29

0 Answers0