简体   繁体   English

jenkins 管道中的以下 git 检出行为有什么区别?

[英]What is the difference between the following git checkout behaviours in a jenkins pipeline?

I'm on a new project in my organisation.我在我的组织中进行一个新项目。 In two different jenkins pipeline I have the following checkout behaviours and I want to understand the difference between the two and when to use which one.在两个不同的 jenkins 管道中,我有以下结帐行为,我想了解两者之间的区别以及何时使用哪一个。 The first one is:第一个是:

                    $class: 'GitSCM',
                    branches: [[name: '*/master']],
                    userRemoteConfigs: [[credentialsId: GIT_CRED_ID, url: REPO_URL]]
                ])

GIT_CRED_ID and REPO_URL are defined variables in the pipeline environment. GIT_CRED_ID 和 REPO_URL 是管道环境中定义的变量。

The second one is:第二个是:

checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false,
extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xxx-key', url: 'https://github.com/xxx']]])

Apart from the branch they are checking out I do not understand when to use which one.除了他们正在检查的分支之外,我不明白何时使用哪个分支。

tl;dr no, there is no difference. tl;博士不,没有区别。 Use the shorter one to make your code compacter/readable or the longer to show all possible class parameters使用较短的以使您的代码更紧凑/可读,或使用较长的以显示所有可能的 class 参数

Longer更长

The step checkout syntax is basically the class to use ( GitSCM ) followed by the parameters of the class constructor.步骤检出语法基本上是要使用的 class ( GitSCM ),后跟 class 构造函数的参数。 The difference between the two calls you mentioned is, in the first one you only give two parameters (repository and remote configs) and in the second one, you give a lot more parameters.您提到的两个调用之间的区别在于,在第一个调用中您只提供两个参数(存储库和远程配置),而在第二个调用中,您提供了更多参数。

But what you asked is: makes that any difference?但你问的是:这有什么不同吗?

Unfortunatelly, documentation in Jenkins plugins is kind of sort.不幸的是,Jenkins 插件中的文档有点像。 Or better said, the documentation is the source code itself.或者更好地说,文档就是源代码本身。 If you google for GitSCM github , the first link you get is the source code of the class, you can have a look into what all those class parameters mean:如果你用谷歌搜索GitSCM github ,你得到的第一个链接是 class 的源代码,你可以看看所有这些 class 参数的含义:

https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java

So if you have a look into the constructor parameters, you notice that the second call you mentioned just gives the default input parameter values因此,如果您查看构造函数参数,您会注意到您提到的第二个调用只是给出了默认输入参数值

I think both are same.我认为两者都是一样的。 In the first approach, looks like you are missing starting snippet.在第一种方法中,看起来您缺少起始片段。 The best way to understand is know the Plugins installed in Jenkins for this methods.了解此方法的最佳方法是了解 Jenkins 中安装的插件。 You can see the logs of the pipelines and try to understand, whether these pipelines are checking out only Single Branch, that you want or Cloning all branches and later checking out the desired branch.您可以查看管道的日志并尝试了解这些管道是仅签出您想要的单个分支,还是克隆所有分支,然后再签出所需的分支。 If both are doing the same without any Issue, you can choose any one of them.如果两者都在做同样的事情而没有任何问题,您可以选择其中任何一个。 You can prefer stable plugin code.您可以更喜欢稳定的插件代码。

Looks like, you are using SCM step plugin.看起来,您正在使用 SCM 步骤插件。 Once verify with team, who has installed the plugins.一旦与团队核实,谁安装了插件。https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM