I have build step in my jenkins-pipeline:
stage('Build') {
agent {
docker {
image 'mymvnbasedimage:latest'
args '-u root:root'
reuseNode true
}
}
steps {
sh "ant"
}
}
It works, everything is fine. But, then the workspace
will contains directory and files owned by root
which can not be deleted by the user jenkins
at the next run when cleaning the workpace
.
ls -lt ~/workspace/myjenkinsjob/dist/
total 185764
-rw-r--r-- 1 root root 190218240 Aug 3 19:49 buildresult-21.tar
O f course i can add:
stage('Chown to user Jenkins'){
steps {
echo 'Chown to user Jenkins'
sh "sudo chown -R jenkins:jenkins ${WORKSPACE}"
}
}
But it is not ok, because i have to add in the /etc/sudoers
rights to make chown
for user Jenkins
. Also, i can't make inside container operation of chown
, because there user jenkins
does not exists. Which variant, you can advice ? Please help.