ws() 块在 Jenkins 中有什么作用? [英] What does a ws() block do in Jenkins?
本文介绍了ws() 块在 Jenkins 中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 Jenkinsfile">脚本化管道 到 声明性管道.我在 Jenkinsfile
中有这样的块:
I'm trying to convert few Jenkinsfile
s 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, sincenode
will also ensure that it gets run with a separate executor. - this provides more isolation than the
dir
step, sincedir
will not ensure an isolated location on the filesystem the wayws
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/管道插件/blob/master/TUTORIAL.md#allocating-workspaces
这篇关于ws() 块在 Jenkins 中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文