在詹金斯中,ws()块有什么作用? [英] What does a ws() block do in Jenkins?

查看:728
本文介绍了在詹金斯中,ws()块有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从脚本化管道声明性管道.我在Jenkinsfile中有一个这样的块:

I'm trying to convert few Jenkinsfiles from Scripted Pipeline to Declarative Pipeline. I have a block like this in a Jenkinsfile:

ws("/path/to/dir") {
    // do stuff
}

我想知道它到底能做什么,以及将其转换为声明性管道语法的正确方法是什么.

I wonder what does it do exactly and what's the proper way to convert it to the Declarative Pipeline syntax.

推荐答案

ws分配新的工作区.您将使用它来确保没有其他任何干扰在磁盘上运行所附步骤的位置.

ws allocates a new workspace. you would use this to ensure that nothing else interferes with the location on disk where you are running the enclosed steps.

  • 这并不像node步骤那样繁琐,因为node还将确保它由单独的执行程序来运行.
  • 这比dir步骤提供了更多的隔离,因为dir不能像ws那样确保文件系统上的隔离位置.
  • this is not as heavy-handed as the node step, since node will also ensure that it gets run with a separate executor.
  • this provides more isolation than the dir step, since dir will not ensure an isolated location on the filesystem the way ws will.

您可以按照与脚本相同的方式在声明性管道中使用它:

you can use it in a declarative pipeline in the same way as scripted:

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] ws
Running in /tmp/hey
[Pipeline] {
[Pipeline] sh
[hey] Running shell script
+ pwd
/tmp/hey

参考:

  • https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-ws-code-allocate-workspace
  • https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md#allocating-workspaces

这篇关于在詹金斯中,ws()块有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆