Jenkinsfile Dockerfile binding volume pwd

Viewed 619

Jenkins is running in a docker container (this works). In a job using a Jenkinsfile I am trying to bind a volume to the current working directory in Jenkins to a path in the job container, however I am failing to get the value of the current working directory to work. I've tried env.WORKSPACE and pwd() but the job errors out. How should I be declaring the equivalent of -v $(pwd):/workdir? And how would I add additional volumes?

My Dockerfile.job is simply:

FROM crops/poky:ubuntu-18.04

RUN /bin/bash -c 'echo La la la'

ENV myblah="my blah variable" \
    otherblah="this is another bla variable"
    
ADD entrypoint.sh /

ENTRYPOINT [ "/entrypoint.sh" ]

The Jenkinsfile stage that is giving me grief is something like this:

stage('this problematic stage') {
    agent {
       dockerfile {
           filename 'Dockerfile.job'
           args "-v ${pwd()}:/workdir"  // <- help! this doesn't work
      }
    }
    steps {
      // this works fine if I comment out my args above
      echo "yoohoo"
      sh 'echo myblah = $myblah'
      sh 'echo otherblah = $otherblah' 
}

For the curious entrypoint.sh is a copy paste from JENKINS bug 51307

!/bin/sh
# Workaround script for Jenkins bug: https://issues.jenkins-ci.org/browse/JENKINS-51307
set -e

# check if there was a command passed
# required by Jenkins Docker plugin: https://github.com/docker-library/official-images#consistency
if [ "$1" ]; then
    # execute it
    exec "$@"
fi

# else run my script
exec ls -la
0 Answers
Related