Skip to main content

Command Palette

Search for a command to run...

How to Connect Jenkins with GitHub

Part 2

Published
3 min read

In Jenkins, you can create automation workflows (pipelines) using Freestyle projects or Pipeline projects. Let’s see the differences:

Freestyle Project

  • Simple and easy to create

  • No coding required

  • Suitable for small, simple jobs

Limitations:

  • Hard to manage for complex or large workflows

  • Not ideal for real-time, production-grade CI/CD pipelines

Pipeline Project

  • Most commonly used in real-world projects

  • Written as code (Jenkinsfile) → easy to version control

  • Supports complex workflows, stages, and parallel tasks

  • Easier to maintain, extend, and manage

The best way to learn easy start with freestyle and step into pipeline

Let’s create a Freestyle project and get a code from github to jenkins

Open Jenkins URL in your browser

http://<public-ip-address>:8080
  • Click “New Item” on the left menu.

  • Enter a name for your project (e.g., MyFirstFreestyle).

  • Select Freestyle project and click OK.

Configure your project by selecting the source code management and specifying the branch name correctly. If the repository is private, provide the necessary credentials as well.

Providing Credentials in Jenkins for a Private GitHub Repo

Creating Token in Github

  1. Go to GitHub → Settings → Developer Settings → Personal Access Tokens → Tokens (classic)

  2. Click Generate new token → give a name/description

  3. Select Scopes:

    • repo (full control of private repositories)

    • workflow (optional if using GitHub Actions)

  4. Click Generate token → copy the token (you won’t see it again)

Note: This token will act as your password.

Add Credentials in Jenkins

  1. Open Jenkins → Manage Jenkins → Credentials → System → Global credentials (unrestricted)

  2. Click Add Credentials

  3. Choose:

    • Kind: Username with password

    • Username: your GitHub username

    • Password: the personal access token you just generated

    • ID: optional, e.g., github-private

    • Description: e.g., GitHub Private Repo Token

  4. Click OK

Common Issues You May Encounter

  • Git not installed – Make sure Git is installed on your Jenkins server.

  • Port blocked – Check that the security group allows the required port (usually 8080).

  • Credentials not selected – After creating credentials for a private repo, make sure you select them in your job configuration.

  • Wrong branch name – Many repos use main instead of master. Check the branch specifier in your job.

  • Empty repository – If your GitHub repo has no commits, Jenkins cannot build anything.

Conclusion

Connecting Jenkins with GitHub is an important step for automating your development workflow. Freestyle projects are good for beginners and simple tasks, while Pipeline projects are better for complex workflows. For private repositories, setting up credentials ensures secure access. By following these steps, you can create CI/CD pipelines, avoid common issues, and make your development process faster, smoother, and more reliable.

If you found this guide useful, please like ❤️, comment, and share your thoughts or questions. Stay tuned for the next part, where we'll explore advanced Docker concepts and practices.

Thank you,
Yours, Rama Grandhi