jenkins pipeline之stash/unstash


在使用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都沒有執行

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM