簡體   English   中英

無法在詹金斯中使用Multiple-SCM-Plugin獲得多個倉庫的git commit

[英]Cannot get git commits for multiple repos using Multiple-SCM-Plugin in Jenkins

因此,我配置了一個詹金斯工作,該工作可以從3個倉庫中檢出master分支。 現在,我想獲取所有三個存儲庫的最新更改。

當前,GIT_COMMIT env變量僅提供對配置中添加的最后一個存儲庫的提交,而對所有三個都沒有。

有什么辦法可以獲取所有三個存儲庫的先前提交和當前git提交?

我遇到了同樣的問題,並決定派出多個SCM插件來修復它: https : //github.com/JakeStoeffler/multiple-scms-plugin

如果願意,只需克隆我的存儲庫並運行mvn即可構建HPI文件(位於target/multiple-scms.hpi ),您可以手動上載並安裝在Jenkins中。 如果您想自己進行調整,請直接克隆原始存儲庫 ,打開MultiSCM.java ,然后將buildEnvVars()方法中的代碼替換為以下內容:

@Override
public void buildEnvVars(AbstractBuild<?,?> build, Map<String, String> env) {
    // Add each SCM's env vars, appending indices where needed to avoid collisions
    for (int i = 0; i < scms.size(); i++) {
        try {
            EnvVars currScmVars = new EnvVars();
            scms.get(i).buildEnvVars(build, currScmVars);
            for (Entry<String, String> entry : currScmVars.entrySet()) {
                if (env.containsKey(entry.getKey())) {
                    // We have a collision; append the index of this SCM to the env var name
                    env.put(entry.getKey() + "_" + i, entry.getValue());
                } else {
                    // No collision; just put the var as usual
                    env.put(entry.getKey(), entry.getValue());
                }
            }
        }
        catch(NullPointerException npe) {}
    }
}

希望那里的評論很不言自明。 基本上,原始代碼中的錯誤是,當您有多個具有相同環境變量名稱的SCM時,這些變量在被迭代時會被覆蓋。 我們通過防止這些覆蓋,而是在變量名后附加索引來解決此問題。

這是一個使用它的示例:如果我們的項目配置了3個Git SCM,我們現在可以使用env vars GIT_COMMITGIT_COMMIT_1GIT_COMMIT_2來單獨訪問每個Git存儲庫的最新提交哈希。 附加的索引對應於Jenkins中項目配置中SCM的順序。

顯然,這是一個快速而骯臟的解決方案,但是它可以滿足我的需要。 隨意定制它以滿足您的需求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM