Jenkins pipeline git command submodule update

前端 未结 3 1557
甜味超标
甜味超标 2020-12-08 02:31

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         


        
3条回答
  •  青春惊慌失措
    2020-12-08 03:25

    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.

提交回复
热议问题