Jenkins 管道 git 命令子模块更新 [英] Jenkins pipeline git command submodule update

查看:73
本文介绍了Jenkins 管道 git 命令子模块更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新 git clone 上的子模块.

I want to update submodule on git clone.

有没有办法用 Jenkins 管道 Git 命令来做到这一点?

Is there a way to do this with Jenkins pipeline Git command?

目前我正在这样做...

Currently I'm doing this...

git branch: 'master',
    credentialsId: 'bitbucket',
    url: 'ssh://bitbucket.org/hello.git'

但是一旦克隆它就不会更新子模块

It doesn't however update submodule once cloned

推荐答案

使用当前的 Git 插件,你甚至不需要那个.

With the current Git plugin, you don't even need that.

GIT 插件支持带有子模块的存储库,而子模块本身又具有子模块.
不过必须开启此功能:

The GIT plugin supports repositories with submodules which in turn have submodules themselves.
This must be turned on though:

在作业配置-> 部分源代码管理,Git -> 高级按钮(在要构建的分支下)-> 递归更新子模块

in Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules

但是 OP 正在使用管道.

But the OP is using pipeline.

所以简单的第一个构建步骤就足够了:

So a simple first build step is enough:

git submodule update --init --recursive

但是,OP 补充说:

是的,但如果我使用 sh 'git submodule update --init --recursive',这将使用 $HOME/id_rsa 对吗?如果可能的话,我想为这个命令传递我的私钥.

Yes but if I'm using sh 'git submodule update --init --recursive', this will use $HOME/id_rsa right? I want to pass in my private key for this command if possible.

有可能:在管道语法中,您可以定义环境变量.
这意味着您可以设置 GIT_SSH_COMMAND(使用 Git 2.10+).
这允许您引用您自己的私钥.

It is possible: In the Pipeline syntax, you can define environment variables.
Which means you can set GIT_SSH_COMMAND (with Git 2.10+).
That allows you to reference your own private key.

pipeline {
    agent any

    environment {
        GIT_SSH_COMMAND = 'ssh -i /path/to/my/private/key'
    }

    stages {
        stage('Build') {
            steps {
                sh 'printenv'
                sh 'git submodule update --init --recursive'
            }
        }
    }
} 

如果任何克隆涉及 ssh url,则该 ssh 克隆将使用正确的私钥.

If any clone involve an ssh url, that ssh clone will use the right private key.

这篇关于Jenkins 管道 git 命令子模块更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆