ws分配一个新的工作区。您将使用它来确保其他任何因素都不会干扰磁盘上运行所附步骤的位置。
- 这不会像
node
步骤那样繁重,因为node
这还将确保它由单独的执行程序运行。 - 这将提供比
dir
步骤更多的隔离,因为这dir
将无法确保在文件系统上的隔离位置ws
。
您可以按照与脚本相同的方式在声明性管道中使用它:
pipeline { agent { label 'docker' } stages { stage('hot_stage') { steps { sh 'pwd' ws('/tmp/hey') { sh 'pwd' } } } }}产生输出:
+ pwd/opt/jenkins/workspace/tool_jenkins2-test_master-R4LIKJR63O6POQ3PHZRAKWWWGZZEQIVXVDTM2ZWZEBAWE3XKO6CQ[Pipeline] wsRunning in /tmp/hey[Pipeline] {[Pipeline] sh[hey] Running shell script+ pwd/tmp/hey参考资料:
- https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#pre-ws-pre-allocate-workspace
- https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md#allocating-workspaces



