Git命令从开发分支签出最新提交 [英] Git command to checkout latest commit from develop branch

查看:526
本文介绍了Git命令从开发分支签出最新提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins管道中使用groovy语法,以下是用于签出的语法:

Using groovy syntax in Jenkins pipeline, below is the syntax used for check out:

         git branch: branchName, 
                       credentialsId: credential, 
                       url: "${gitLabServer}/${projectName}/${repo}.git"

credential是下面显示的詹金斯凭证(111111-222222-33333-44444):

Where credential is jenkins credential(111111-222222-33333-44444) shown below:

对于时髦的语法,jenkins做了以下工作:

jenkins does the following under the hood, for groovy syntax(above):

Cloning the remote Git repository
Cloning repository ssh://git@10.xx.xx.xx:2222/abc/def.git
 > git init /app/jenkins/workspace/../def # timeout=10
Fetching upstream changes from ssh://git@10.xx.xx.xx:2222/abc/def.git
 > git --version # timeout=10
using GIT_SSH to set credentials abcuser
 > git fetch --tags --progress ssh://git@10.xx.xx.xx:2222/abc/def.git +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url ssh://git@10.xx.xx.xx:2222/abc/def.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url ssh://git@10.xx.xx.xx:2222/abc/def.git # timeout=10
Fetching upstream changes from ssh://git@10.xx.xx.xx:2222/abc/def.git
using GIT_SSH to set credentials abcuser
 > git fetch --tags --progress ssh://git@10.xx.xx.xx:2222/abc/def.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision 5df59884ecb3aa1b55aabf99ab8bd0adcd4eb41b (refs/remotes/origin/develop)
Commit message: "new commit"


对于给定的常规语法,要在shell上运行的等效git命令足以满足要求? git clone -branchgit checkout是否不够?为什么Jenkins多次运行git fetch?


For the given groovy syntax, What is the equivalent git command suffice to run on shell? Does git clone -branch or git checkout would not suffice? Why Jenkins is running git fetch multiple times?

推荐答案

从我看到的情况来看,需要进行以下操作.您在詹金斯(Jenkins)的凭据需要是私钥.

From what I see, following need to happen. Your credential in Jenkins need to be a private key.

身份验证阶段:

# optional. check whether the gitLabServer is already trusted
ssh-keygen -F ${gitLabServer} 
# adds the gitLabServer into known_hosts. This stops interactive prompts during git clone.
ssh-keyscan ${gitLabServer} >> ~/.ssh/known_hosts

# Add your existing private key (like id_rsa) into authentication agent
eval `ssh-agent -s`
ssh-add /path/to/key/credential

Git克隆阶段:

# Finally, clone the repo with branchName as a parameter
git clone -b ${branchName} git@${gitLabServer}:${projectName}/${repo}.git

这篇关于Git命令从开发分支签出最新提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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