简体   繁体   中英

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. 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.

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. Use the shorter one to make your code compacter/readable or the longer to show all possible class parameters

Longer

The step checkout syntax is basically the class to use ( GitSCM ) followed by the parameters of the class constructor. 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. 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:

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. 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. Once verify with team, who has installed the plugins.https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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