0

This is a snippet from my Jenkinsfile:

        stage('Checkout project') {
            checkout scm
        }
        scalaImage = docker.image('<myNexus>/centos-sbt:2.11.8')
        stage('Test project') {
            docker.withRegistry('<myNexus>', 'jenkins-nexus') {
                scalaImage.inside('-v /var/lib/jenkins/.ivy2:/root/.ivy2') { c ->
                    sh 'sbt clean test'
                }
            }
        }

When I look in the docs for what .inside does I find:

  1. Automatically grab a slave and a workspace (no extra node block is required).
  2. Pull the requested image to the Docker server (if not already cached).
  3. Start a container running that image.
  4. Mount the Jenkins workspace as a “volume” inside the container, using the same file path

My question is regarding the last two words of point 4. Is there a way to get the file path that the plugin is using to mount the code into the docker container?

Thank you.

zaxme
  • 1,065
  • 11
  • 29
  • `env.WORKSPACE` will give you the path to what is being mounted. By convention right now, it is mapped to a directory of the same exact name in the container but that may have changed in recent versions. This currently sounds like an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) - what are you actually trying to do? – mkobit Nov 21 '17 at 14:17

2 Answers2

0

If you are using CloudBees plugin. It will automatically mount your current Workspace to the docker image.

Ram
  • 1,154
  • 6
  • 22
  • That's exactly the problem. I don't know the name of the workspace that the plugin is mounting so if I want to mount something there myself - like a cache directory for sbt - I cannot do it. – zaxme Nov 22 '17 at 12:31
  • its always pwd which is mounted which is ${WORKSPACE}/scmDir. If you want to mount custom volumes, pass them as map. Kindly check this https://github.com/SAP/cloud-s4-sdk-pipeline-lib/blob/master/vars/executeDockerNative.groovy/#L11 – Ram Nov 22 '17 at 13:16
0

As described in here: pwd() is what I needed.

node('label'){
    //now you are on slave labeled with 'label'
    def workspace = pwd()
    //${workspace} will now contain an absolute path to job workspace on slave 
}
zaxme
  • 1,065
  • 11
  • 29