Get absolute path to workspace directory in Jenkins Pipeline plugin

前端 未结 4 1944
南方客
南方客 2020-12-01 15:21

I\'m currently doing some evaluation on the Jenkins Pipeline plugin (formerly know as Workflow plugin). Reading the documentation I found out that I currently cannot retriev

4条回答
  •  囚心锁ツ
    2020-12-01 16:10

    Since version 2.5 of the Pipeline Nodes and Processes Plugin (a component of the Pipeline plugin, installed by default), the WORKSPACE environment variable is available again. This version was released on 2016-09-23, so it should be available on all up-to-date Jenkins instances.

    Example

    node('label'){
        // now you are on slave labeled with 'label'
        def workspace = WORKSPACE
        // ${workspace} will now contain an absolute path to job workspace on slave
    
        workspace = env.WORKSPACE
        // ${workspace} will still contain an absolute path to job workspace on slave
    
        // When using a GString at least later Jenkins versions could only handle the env.WORKSPACE variant:
        echo "Current workspace is ${env.WORKSPACE}"
    
        // the current Jenkins instances will support the short syntax, too:
        echo "Current workspace is $WORKSPACE"
    
    }
    

提交回复
热议问题