How to cleanup workspace built from docker

classic Classic list List threaded Threaded
4 messages Options
Den
Reply | Threaded
Open this post in threaded view
|

How to cleanup workspace built from docker

Den
Hi,

I'm building artifacts in docker image and if I'm aborting a build, the deleteDir function fails to delete artifacts since
they were created with root user in docker and the function is called by jenkins user outside of docker. Is there any workaround?

pipeline {
    agent {label 'docker'}
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'adoptopenjdk/openjdk8' args '-u root -v $HOME/.m2:/root/.m2' reuseNode true label 'docker'
                }
            }
            stages {
                stage ('Package') {
                        sh "./mvnw package"
                }
            }
    post {
always {deleteDir()}
    }
        }
    }
    post {
        always {deleteDir()}
    }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a189d9e3-5f00-4144-a561-f720f797f9b8%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to cleanup workspace built from docker

Gianluca
The best solution is not run any command as root inside docker.
Use the environment variables UID and GID and run the docker with a user corresponding to the UID and GIU; something like "--user $UID:$GID" instead of root



On Tuesday, 12 May 2020 08:51:43 UTC+1, Den wrote:
Hi,

I'm building artifacts in docker image and if I'm aborting a build, the deleteDir function fails to delete artifacts since
they were created with root user in docker and the function is called by jenkins user outside of docker. Is there any workaround?

pipeline {
    agent {label 'docker'}
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'adoptopenjdk/openjdk8' args '-u root -v $HOME/.m2:/root/.m2' reuseNode true label 'docker'
                }
            }
            stages {
                stage ('Package') {
                        sh "./mvnw package"
                }
            }
    post {
always {deleteDir()}
    }
        }
    }
    post {
        always {deleteDir()}
    }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/04843dc4-4e57-4b65-9aa0-11f78f62efcd%40googlegroups.com.
Den
Reply | Threaded
Open this post in threaded view
|

Re: How to cleanup workspace built from docker

Den
And how to mount .m2 directory then? Currently I do: args '-u root -v $HOME/.m2:/root/.m2'

Am Dienstag, 12. Mai 2020 10:21:52 UTC+2 schrieb Gianluca:
The best solution is not run any command as root inside docker.
Use the environment variables UID and GID and run the docker with a user corresponding to the UID and GIU; something like "--user $UID:$GID" instead of root



On Tuesday, 12 May 2020 08:51:43 UTC+1, Den wrote:
Hi,

I'm building artifacts in docker image and if I'm aborting a build, the deleteDir function fails to delete artifacts since
they were created with root user in docker and the function is called by jenkins user outside of docker. Is there any workaround?

pipeline {
    agent {label 'docker'}
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'adoptopenjdk/openjdk8' args '-u root -v $HOME/.m2:/root/.m2' reuseNode true label 'docker'
                }
            }
            stages {
                stage ('Package') {
                        sh "./mvnw package"
                }
            }
    post {
always {deleteDir()}
    }
        }
    }
    post {
        always {deleteDir()}
    }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f72de1d2-de92-436a-81c4-eb573fe995de%40googlegroups.com.
Den
Reply | Threaded
Open this post in threaded view
|

Re: How to cleanup workspace built from docker

Den
In reply to this post by Gianluca
If I omit -u root then jenkins uses 'docker run -t -d -u 993:990 -v $HOME/.m2:/root/.m2' command to run the image. That works, but it will download all dependencies every time. When using root user, the repository is mounted and maven uses already downloaded dependencies.

Am Dienstag, 12. Mai 2020 10:21:52 UTC+2 schrieb Gianluca:
The best solution is not run any command as root inside docker.
Use the environment variables UID and GID and run the docker with a user corresponding to the UID and GIU; something like "--user $UID:$GID" instead of root



On Tuesday, 12 May 2020 08:51:43 UTC+1, Den wrote:
Hi,

I'm building artifacts in docker image and if I'm aborting a build, the deleteDir function fails to delete artifacts since
they were created with root user in docker and the function is called by jenkins user outside of docker. Is there any workaround?

pipeline {
    agent {label 'docker'}
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'adoptopenjdk/openjdk8' args '-u root -v $HOME/.m2:/root/.m2' reuseNode true label 'docker'
                }
            }
            stages {
                stage ('Package') {
                        sh "./mvnw package"
                }
            }
    post {
always {deleteDir()}
    }
        }
    }
    post {
        always {deleteDir()}
    }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b27a45e0-2ead-41c2-a1f8-4c860d171459%40googlegroups.com.