The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps section of the Pipeline Syntax page.

For a list of other such plugins, see the Pipeline Steps Reference page.

Table of Contents

Git plugin

git: Git

Git step. It performs a clone from the specified repository.

Use the Pipeline Syntax Snippet Generator to generate a sample pipeline script for the git step. More advanced checkout operations require the checkout step rather than the git step. Examples of the git step include:

See the argument descriptions for more details.

The git step is a simplified shorthand for a subset of the more powerful checkout step:

checkout([$class: 'GitSCM', branches: [[name: '*/master']],
    userRemoteConfigs: [[url: 'http://git-server/user/repository.git']]])

NOTE: The checkout step is the preferred SCM checkout method. It provides significantly more functionality than the git step.

Use the Pipeline Syntax 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 git step does not support:

  • SHA-1 checkout
  • Tag checkout
  • Submodule checkout
  • Sparse checkout
  • Large file checkout (LFS)
  • Reference repositories
  • Branch merges
  • Repository tagging
  • Custom refspecs
  • Timeout configuration
  • Changelog calculation against a non-default reference
  • Stale branch pruning

Example: Git step with defaults

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

The Pipeline Syntax Snippet Generator generates this example:

git 'https://github.com/jenkinsci/git-plugin'

Example: Git step with https and a specific branch

Checkout from the Jenkins source repository using https protocol, no credentials, and a specific branch (stable-2.204). Note that this must be a local branch name like 'master' or 'develop'.

Branch names that are not supported by the git step

  • Remote branch names like 'origin/master' and 'origin/develop' are not supported as the branch argument
  • SHA-1 hashes are not supported as the branch argument
  • Tag names are not supported as the branch argument

Remote branch names, SHA-1 hashes, and tag names are supported by the general purpose checkout step.

The Pipeline Syntax Snippet Generator generates this example:

git branch: 'stable-2.204',
    url: 'https://github.com/jenkinsci/jenkins.git'

Example: Git 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 Syntax Snippet Generator generates this example:

git credentialsId: 'my-private-key-credential-id',
    url: 'git@github.com:jenkinsci/git-client-plugin.git'

Example: Git 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 Syntax Snippet Generator generates this example:

git changelog: false,
    url: 'https://github.com/jenkinsci/credentials-plugin.git'

Example: Git step with https protocol and polling disabled

Checkout from the Jenkins platform labeler repository using https 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 Syntax Snippet Generator generates this example:

git poll: false,
    url: 'https://github.com/jenkinsci/platformlabeler-plugin.git'

Argument Descriptions
  • url

    URL of the repository to be checked out in the workspace. Required parameter.

    Repository URL's should follow the git URL guidelines. Git steps to access a secured repository should provide a Jenkins credential with the credentialsId argument rather than embedding credentials in the URL. Credentials embedded in a repository URL may be visible in console logs or in other log files.

    • Type: String
  • branch (optional)

    Branch to be checked out in the workspace. Default is 'master'.

    Note that this must be a local branch name like 'master' or 'develop'. Remote branch names like 'origin/master' and 'origin/develop' are not supported as the branch argument. Tag names are not supported as the branch argument. SHA-1 hashes are not supported as the branch argument. Remote branch names, tag names, and SHA-1 hashes are supported by the general purpose checkout step.

    • Type: String
  • changelog (optional)

    Compute changelog for this job. Default is 'true'.

    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.

    • Type: boolean
  • credentialsId (optional)

    Identifier of the credential used to access the remote git repository. Default is '<empty>'.

    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.

    • Type: String
  • poll (optional)

    Poll remote repository for changes. Default is 'true'.

    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.

    • Type: boolean

Was this page helpful?

Please submit your feedback about this page through this quick form.

Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

    


See existing feedback here.