将变量传递给另一个管道 Jenkins

Pass variables to another pipeline Jenkins

我的目标是从 pipeApipeB 获取变量。

pipeA 完成后,它会创建新的应用程序版本并将其上传到 AWS S3。

pipeB 中,我想获取所有上传到 S3 的应用程序版本,因此我需要将 appNames 传递到某个地方。

然后当我用参数构建 pipeB 时,我想在构建之前将所有 appName 作为参数获取,但我不知道如何。

Jenkins ver: 2.141

Example pre build step

大量编辑 工作流程是

  1. 向 S3 询问变量
  2. 将此变量作为选择参数
  3. Select Jenkins UI 一些参数
  4. 执行管道

在本例中 Active Choices Reactive Parameter,内部使用 groovy 脚本和 return。例如:

//S3 file request 
response = ["curl", "-k", 
"-H", "Host: ${bucket}.s3.amazonaws.com", 
"-H", "Date: ${dateValue}", 
"-H", "Authorization: AWS ${s3Key}:${signature}", 
"https://${bucket}.s3.amazonaws.com/${file}"].execute().text 


def choices = []
response.eachLine {
    if (it.contains("Not Found")) {choices.push("There is no file")}
    //here parse your file, in my example is flat custom text
    else {
        if (!it.contains("  ")) {
            param= it.replace(":", "")
            choices.push(param)
        }
    }        
} 
def clean = choices.findAll { item -> !item.isEmpty() } 
return clean.sort() 

这样你需要插入一些参数,当然最简单的方法是在groovy脚本中以纯文本形式定义它:

def bucket = '13dfvcqe'
def dateValue = '123'
def s3Key = '1452234F'
def signature = '2133'
def file  = 'vars'

这既简单又危险 :) 更好的选择是在该参数之前将此机密值填充为 Jenkins password parameter 并使用 Referenced parameters 选项。