jenkins pipeline之stash/unstash

本文介绍了Jenkins Pipeline中的stash和unstash功能。stash用于临时存储文件,将其打包为tar包,但可能消耗CPU并有限制,建议文件大小在100M以下。与archive的区别在于,stash在任务完成后会删除文件,而archive会持久保存并在 Jenkins 页面显示。使用时要注意stash只能在最后使用一次,多次使用会被忽略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用jenkins时,经常会问到文件怎么存储?

正好jenkins有一个stash的功能,下面简单介绍下:

先看看官方是怎么解释的:

stash: Stash some files to be used later in the build
Saves a set of files for use later in the same build, generally on another node/workspace. 
Stashed files are not otherwise available and are generally discarded at the end of the build.
Note that the stash and unstash steps are designed for use with small files.
For large data transfers, use the External Workspace Manager plugin, or use an external repository manager such as Nexus or Artifactory.
This is because stashed files are archived in a compressed TAR,
and with large files this demands considerable on-master resources, particularly CPU time.
There's not a hard stash size limit, but between 5-100 MB you should probably consider alternatives.

  大致翻译下就是:

   暂时将文件存储起来(具体存在哪,没看到管方解释),后需通过unstash方式调用

   但是呢:

      stash会将文件打包成一个tar包来敦促,所以大文件时会耗CPU,而且stash有文件大小限制,尽量在100M以下

 

除了stash方法,还有一个archive的方法也可以存文件

但是这二者区别是:

   stash会在pipeline任务结束后将文件全部删除,而archive会一直保存文件,且在jenkins页面上显示

 

在实际使用过程中,有一点需要注意的是:

stash只能放在最后,且只能一次,多次是不执行的,如下面方式是错误的

stash includes: 'aa\\*', name: BUILD_NUMBER
stash includes: 'bb\\*', name: bb

实际测试中发出,只会stash aa文件夹内容,后面的bb stash都没有执行

 

转载于:https://www.cnblogs.com/landhu/p/10880321.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值