简体   繁体   English

如何在 Jenkins 上使用多分支管道在分支之间重用工作空间?

[英]How to reuse workspaces between branches with multibranch pipeline on Jenkins?

I've set up multibranch pipeline to track my repo and automatically build and test for all merge requests.我已经设置了多分支管道来跟踪我的回购并自动构建和测试所有合并请求。 It works wonders, however, I noticed that Jenkins creates a new workspace for each new branch.它创造了奇迹,但是,我注意到 Jenkins 为每个新分支创建了一个新的工作区。 It is a pretty big project with a heavy build process and a lot of non-tracked cache files, that mostly stay valid from one version to another - so if instead of a fresh git checkout it would re-use previous workspace, it would build much faster (and also not use up so much hard drive space).这是一个相当大的项目,具有繁重的构建过程和许多未跟踪的缓存文件,从一个版本到另一个版本大多保持有效 - 因此,如果不是新的 git 检出,它将重新使用以前的工作区,它将构建快得多(而且也不会占用太多硬盘空间)。

How can I configure it to re-use the same workspace for different branches?我如何配置它以将相同的工作区重新用于不同的分支?

After researching the issue, I found out that this is not something I can do with multibranch pipeline, so I switched to using the regular pipeline project. 在研究了这个问题之后,我发现使用多分支管道无法做到这一点,因此我转而使用常规管道项目。 Now every build uses one of the available workspaces, so they end up re-using previous workspaces and the same cache files that really speed up the build. 现在,每个构建都使用可用的工作空间之一,因此它们最终会重用以前的工作空间和真正加快构建速度的相同缓存文件。

Jenkins for MultiBranch projects by default uses isolated workspaces for every branch. Jenkins 对于 MultiBranch 项目,默认情况下为每个分支使用独立的工作区。 Jobs within the same branch use the same workspace.同一分支内的作业使用相同的工作区。

A possible solution for you is to use ws(path) inside a pipeline.一个可能的解决方案是在管道内使用ws(path)

node("agent_name") {
    ws(workspacePath) {
        echo '...'      
        // ..
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins 多分支管道在不相关的分支上触发管道 - Jenkins multibranch pipeline triggers pipeline on unrelated branches 如何欺骗Jenkins认为所有分支已经在多分支管道中运行? - How to fool Jenkins into thinking all branches already ran in multibranch pipeline? 如何跨分支限制Jenkins并发多分支管道构建? - How to limit Jenkins concurrent multibranch pipeline builds across branches? 获取 Jenkins 多分支管道中的分支列表 - Get list of branches in Jenkins multibranch pipeline 如何为分支优化Jenkins工作空间 - How to optimize Jenkins workspaces for branches 多分支 Jenkins 管道停止扫描所有分支中的 Jenkins 文件 - Multibranch Jenkins pipeline stop scanning for Jenkins file in all branches 怎么把Jenkins Pipeline转换成Multibranch Pipeline? - How to convert Jenkins Pipeline into Multibranch Pipeline? 我如何使用 Jenkins 和 Pipeline Multibranch 插件跨分支拥有唯一的内部版本号 - How can I have unique build numbers across branches with Jenkins & the Pipeline Multibranch Plugin gradle build with subprojects, git feature branches and jenkins multibranch pipeline: 如何只在受影响的子项目上运行测试 - gradle build with subprojects, git feature branches and jenkins multibranch pipeline: how to only run tests on affected subprojects 如何减少分支过多的 Jenkins 多分支管道中的预检延迟? - How to reduce pre-checkout delay in Jenkins multibranch pipeline with too many branches?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM