Git Integration and SCM

Harry · 12 Sep 2026 · 15 views

Connect Jenkins to Git

In a freestyle job add the source-code step:

  • Repository URL: https://github.com/you/your-app.git
  • Credentials: username/password, SSH key or GitHub app
  • Branches to build: */main

Jenkins clones the repository into the build workspace on every run, so builds are always reproducible.

Triggering Builds

Polling (Jenkins asks Git)

Poll SCM: H/5 * * * *

This checks for changes every 5 minutes (hash-spread). Simple, but adds latency.

Webhooks (Git pushes Jenkins)

On GitHub, add a webhook pointing to http://YOUR_JENKINS/github-webhook/. On GitLab use a Jenkins integration or a generic push event. Webhooks trigger builds immediately - use them in production.

Multibranch Pipelines

A Multibranch Pipeline job scans a repository, finds branches with Jenkinsfiles, and creates a pipeline per branch. Perfect for PR workflows: every pull request gets its own build.

Environment Variables

GIT_COMMIT       # the built commit SHA
GIT_BRANCH       # the branch name
GIT_PREVIOUS_COMMIT
WORKSPACE        # where the checkout lives

Key Points

  • Poll SCM is easy but slow; prefer webhooks for instant builds.
  • Multibranch pipelines automate per-branch and PR builds.
  • Use credentials objects, never hard-code tokens in the URL.
Share this post:

Comments (0)

Please login or register to comment.