首页 > 解决方案 > Jenkins Pipeline - 从远程 git url 读取属性

问题描述

我有一个位于 git 项目中的属性文件。在构建一个单独的项目时,我想读取这个属性文件来提取一些常见的配置。

readProperties 只允许从当前工作区加载文件。

如何从管道中的不同 git 项目中读取属性文件。

标签: jenkinsproperties

解决方案


您可以克隆 repo/只下载属性文件:

node() {

    stage("Clone repo") {
        git url: "https://github.com/ozlevka/go-envinronment.git"
        //fileDownloadOperation url: "https://raw.githubusercontent.com/ozlevka/go-envinronment/master/bbb.properties"
    }

    stage("Read properies") 
    {
        def props = readProperties  file: './bbb.properties'
        for (def key in props.keySet())
        {
            println "key = ${key}, value = ${props[key]}"
        }
    }
}

readPropertiesgitfileDownloadOperation的文档


推荐阅读