The git plugin provides fundamental git operations for Jenkins projects. It can poll, fetch, checkout, and merge contents of git repositories.

The git plugin provides an SCM implementation to be used with the Pipeline SCM checkout step. The Pipeline Syntax Snippet Generator guides the user to select git plugin checkout options and provides online help for each of the options.

Use the Pipeline Snippet Generator to generate a sample pipeline script for the checkout step. Examples of the checkout step include:

See the argument descriptions for more details.

The checkout step provides access to all the Pipeline capabilities provided by the git plugin:

checkout scmGit(userRemoteConfigs: [
                    [ url: 'https://github.com/jenkinsci/git-plugin' ]
                ])


NOTE: The checkout step is the preferred SCM checkout method. For simpler cases that do not require all the capabilities of the git plugin, the git step can also be used.

Use the Pipeline Snippet Generator to generate a sample pipeline script for the checkout step.

The checkout step can be used in many cases where the git step cannot be used. Refer to the git plugin documentation for detailed descriptions of options available to the checkout step. For example, the checkout step supports:


Example: Checkout step with defaults

Checkout from the git plugin source repository using https protocol, no credentials, and the master branch.

The Pipeline Snippet Generator generates this example:

checkout scmGit(userRemoteConfigs: [
                    [ url: 'https://github.com/jenkinsci/git-plugin' ]
                ])

Example: Checkout step with https and a specific branch

Checkout from the Jenkins source repository using https protocol, no credentials, and a specific branch (stable-2.289).

The Pipeline Snippet Generator generates this example:

checkout scmGit(branches: [[name: 'stable-2.289']],
                userRemoteConfigs: [
                    [ url: 'https://github.com/jenkinsci/jenkins.git' ]
                ])

Example: Checkout step with ssh and a private key credential

Checkout from the git client plugin source repository using ssh protocol, private key credentials, and the master branch. The credential must be a private key credential if the remote git repository is accessed with the ssh protocol. The credential must be a username / password credential if the remote git repository is accessed with http or https protocol.

The Pipeline Snippet Generator generates this example:

checkout changelog: false,
         scm: scmGit(userRemoteConfigs: [
                         [ credentialsId: 'my-private-key-credential-id',
                           url: 'git@github.com:jenkinsci/git-client-plugin.git' ]
                         ])

Example: Checkout step with https and changelog disabled

Checkout from the Jenkins source repository using https protocol, no credentials, the master branch, and changelog calculation disabled. If changelog is false, then the changelog will not be computed for this job. If changelog is true or is not set, then the changelog will be computed. See the workflow scm step documentation for more changelog details.

The Pipeline Snippet Generator generates this example:

checkout changelog: false,
         scmGit(userRemoteConfigs: [
                    [ url: 'https://github.com/jenkinsci/credentials-plugin' ]
                ])

Example: Checkout step with git protocol and polling disabled

Checkout from the command line git repository using git protocol, no credentials, the master branch, and no polling for changes. If poll is false, then the remote repository will not be polled for changes. If poll is true or is not set, then the remote repository will be polled for changes. See the workflow scm step documentation for more polling details.

The Pipeline Snippet Generator generates this example:

checkout poll: false,
         scmGit(userRemoteConfigs: [
                    [ url: 'git://git.kernel.org/pub/scm/git/git.git ]
                ])


Argument Descriptions