I am trying to get the current workspace of my Jenkins build using a Groovy pipeline script:
node('master') { // PULL IN ENVIRONMENT VARIABLES // Jenkins makes these variables available for each job it runs def buildNumber = env.BUILD_NUMBER def workspace = env.WORKSPACE def buildUrl = env.BUILD_URL // PRINT ENVIRONMENT TO JOB echo "workspace directory is ${workspace}" echo "build URL is ${env.BUILD_URL}" }
It returns:
[Pipeline] Allocate node : Start Running on master in /Users/Shared/Jenkins/Home/jobs/test/workspace [Pipeline] node { [Pipeline] echo workspace directory is null [Pipeline] echo build URL is http://localhost:8080/job/test/5/ [Pipeline] } //node [Pipeline] Allocate node : End [Pipeline] End of Pipeline Finished: SUCCESS
If you have this plugin pipeline-stage-view-plugin, you can try opening: https://<Your Jenkins hostLport>/job/<job-name>/<build number>/execution/node/3/wfapi/ . You should see "Allocate node : Start" as the step name.
For me just ${WORKSPACE}
worked without even initializing the variable workspace
.
There is no variable included for that yet, so you have to use shell-out-read-file method:
sh 'pwd > workspace' workspace = readFile('workspace').trim()
Or (if running on master node):
workspace = pwd()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With