gpt4 book ai didi

jenkins - ws() block 在 Jenkins 中有什么作用?

转载 作者:行者123 更新时间:2023-12-04 00:51:40 24 4
gpt4 key购买 nike

我正在尝试转换几个 Jenkinsfile来自 Scripted PipelineDeclarative Pipeline .我在 Jenkinsfile 中有这样的 block :

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

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

最佳答案

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] 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
  • 关于jenkins - ws() block 在 Jenkins 中有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43577139/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com