如何在Jenkins共享库函数中存储/取消暂存文件

时间:2018-04-24 12:54:41

标签: jenkins shared-libraries jenkins-pipeline

我试图写一个" stash_files"和" unstash_files"我的共享库类中的方法。

  • stash仅适用于工作区吗?
  • 我是否需要先将file.txt复制到工作区?
  • 我知道stash获取了file_name和一个stash_name(稍后会被取消),它在共享库中是如何工作的?

Jenkinsfile

@Library('Utils')
import org.jenkins.Utils
utils = new Utils(steps)
node() {
stage('first'){
     utils.doit("file.txt")
}}

共享库:

package src.org.jenkins

class Utils implements Serializable {
def steps

Utils(steps) {
    this.steps = steps
}

def doit(filename){
  this.steps.sh "echo hii > /tmp/$filename"
  this.stash_file(filename)
}

def stash_files(filename){
  this.steps.stash filename
}
def unstash_files(filename){
  this.steps.unstash filename

1 个答案:

答案 0 :(得分:0)

这对我有用:

def stash_file(file_name, name){
    this.steps.stash ('includes': file_name, 'name': name)
}

def unstash_file(name){
    this.steps.unstash name
}
相关问题