I am trying to create a Jenkins pipeline to build a sbt project. Currently, I am trying to use docker-sbt to run one sbt test
stage.
The github project tells me to use sbtuser
to run container as non-root user. But when I try to change user using -u sbtuser
in container args it gets stuck.
Moreover -u root --privileged
arg is working for me, but I don’t know if it will cause issue with permissions on my Jenkins worker node.
Dockerfile ->
FROM sbtscala/scala-sbt:eclipse-temurin-17.0.4_1.7.1_3.2.0
WORKDIR /build
Pipeline ->
stage("1"){
steps{
script{
docker.build(SBT_IMAGE_TAG, "./build-release-tools/Jenkins/MultiBranchJob/jdk17-sbt")
}
}
}
stage("2"){
agent {
docker {
image SBT_IMAGE_TAG
label 'test'
reuseNode true
args '-u sbtuser -v $HOME/.ivy2:/home/sbtuser/.ivy2/'
}
}
steps {
sh "sbt -no-colors ${sbtPRtargets}"
}
}
If I replace the args with args '-u root --privileged -v $HOME/.ivy2:/home/sbtuser/.ivy2/'
the sbt commands run fine.
How can I make the stage work in non-privileged mode or using sbtuser
?