Jenkins 声明性管道:仅为管道设置代理时,哪个工作区与阶段相关联? [英] Jenkins declarative pipeline: What workspace is associated with a stage when the agent is set only for the pipeline?

查看:31
本文介绍了Jenkins 声明性管道:仅为管道设置代理时,哪个工作区与阶段相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个声明性管道的示例,其中为管道设置了代理,但未在各个阶段设置:

Here is an example of declarative pipeline where the agent is set for the pipeline but not set in the individual stages:

pipeline {
    agent { node { label 'linux' } }
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Build') {
            steps {
                sh 'make'
            }
        }
    }
}

我发现的有关脚本化管道的文档清楚地表明,将在单个节点块中使用单个工作区,但可能会为多个节点块分配多个工作区,因此有必要在这些步骤之间进行存储,使用外部工作区如果您想确定步骤之间的工作区中的内容,请使用插件等.

Documentation I've found about scripted pipeline makes it clear that a single workspace will be used within a single node block but multiple node blocks might be allocated multiple workspaces, therefore it is necessary to stash between those steps, use the External Workspace Plugin, etc. if you want to be sure of what's in the workspace between steps.

我很难找到有关声明式管道的工作空间保证的文档.对于这个例子,工作空间有什么保证?

I had a hard time finding documentation about workspace guarantees for declarative pipeline. What guarantees about workspaces exist for this example?

我相信在测试类似管道的过程中,我遇到了在不同工作区执行的两个阶段,但我不确定这是怎么回事.我真的很想避免在我的构建步骤之前隐藏我的结帐或使用外部工作区插件,所以我希望有一种方法可以强制我的所有阶段都在一个工作区/一个节点上运行.

I believe I encountered two stages executing in different workspaces during testing of a similar pipeline but I'm not sure that's what was happening. I'd really like to avoid needing to stash my checkout prior to my build step or use the External Workspace plugin so I was hoping there'd be a way to force all my stages to run all in one workspace/on one node.

推荐答案

呈现的管道代码应该只创建一个工作区并在其中运行所有阶段.除非您在任何 stages 中创建新的 agent 指令,否则它不会使用其他节点或工作区.

The Pipeline code presented should only create a single workspace and run all stages in it. Unless you create a new agent directive in any of your stages it will not utilize another node or workspace.

顺便说一句,checkout scm 使用声明式在管道的开头自动发生,因此您无需显式调用它.

btw, checkout scm happens automatically at the beginning of the Pipeline with Declarative so you don't need to explicitly call that out.

这篇关于Jenkins 声明性管道:仅为管道设置代理时,哪个工作区与阶段相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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