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

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

问题描述



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



目前我正在这样做...

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

一旦克隆,它不会更新子模块 使用当前的 Git插件,你甚至不需要它。


GIT插件支持具有子模块的存储库,子模块本身又具有子模块。

这必须打开:

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


但是OP正在使用管道。



因此,一个简单的第一个构建步骤就足够了:

  git子模块update --init - 递归

然而,OP增加了:


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


有可能:在定义环境变量
这意味着您可以设置 GIT_SSH_COMMAND with Git 2.10+ )。

这可以让你引用您自己的私钥

  pipeline {
代理任何

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

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

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


I want to update submodule on git clone.

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

解决方案

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

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

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

But the OP is using pipeline.

So a simple first build step is enough:

git submodule update --init --recursive

However, the OP adds:

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.

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'
            }
        }
    }
} 

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

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

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