Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to access WORKSPACE inside Jenkinsfile pipelines.agent.dockerfile

I'm trying to mount the workspace as a volume when using Jenkinsfile, but am getting an error that WORKSPACE does not exist as a binding.

pipeline {
  agent {
    dockerfile {
      filename 'Dockerfile'
      dir 'docker/build_env'
      args "-v ${WORKSPACE}/source:/slate/source -v ${WORKSPACE}/build:/slate/build"
    }
  }
}

And the error is:

groovy.lang.MissingPropertyException: No such property: WORKSPACE for class: groovy.lang.Binding

I've also tried ${env.WORKSPACE} but this resolves as null and pwd() which resolved to a class name. I've previously used ${WORKSPACE} successfully before so I'm at a loss.

Please can someone help with what I'm doing wrong?

Thanks.

like image 682
arrkaye Avatar asked Sep 11 '25 09:09

arrkaye


1 Answers

The answer is quotation marks. "-v ${WORKSPACE}/source:/slate/source -v ${WORKSPACE}/build:/slate/build" should be '-v ${WORKSPACE}/source:/slate/source -v ${WORKSPACE}/build:/slate/build'

like image 119
arrkaye Avatar answered Sep 13 '25 20:09

arrkaye