Switch environment in docker file instead of in maven command

I am trying to run parallel builds using jenkins file and docker . I am currently able to run maven commands by putting a -f tag in maven command. I however want to move this in docker to decouple that from jenkinsfile

  • I tried adding WORKDIR in dockerfile and trying to switch
  • I tried using this in copyDocker.inside with “-w /containerworkspace” no luck



FROM artifactory.XXX.XXXX.com/${BASE}

ADD . /containerworkspace/
RUN chmod -R 777 /containerworkspace

jenkinsfile code

def builtImage = self.docker.build(
                        " --build-arg BASE=${imageName}"
                                + " -f ${dockerFile}")
BBDocker copyDocker = dockerBuild.clone()

copyDocker.image("${imageName}:${branchNumber}-${buildNumber}").inside (){
self.sh("mvn -U clean install -f /containerworkspace/")

I am trying to eliminate -f /containerworkspace/ from maven and put it into docker file somehow.

Source: StackOverflow