Jenkins CI/CD for GitHub using Deploy Keys

Continuous Integration and Continuous Deployment (CI/CD) are critical components of modern software development. Jenkins is a popular open-source tool that can be used to automate these processes, making software development faster, more reliable, and easier to manage. This article will explain how to set up Jenkins CI/CD for GitHub using Deploy Keys, a secure and efficient way to connect Jenkins to your GitHub repository.

Prerequisites

  • A GitHub account
  • A Jenkins server with the GitHub plugin installed
  • A repository in GitHub that you want to use with Jenkins

Setting up Deploy Keys

Deploy Keys are SSH keys that are used to grant Jenkins access to your GitHub repository. To set up Deploy Keys, follow these steps:

  1. Log in to your GitHub account and go to your repository.
  2. Click on the “Settings” tab and then “Deploy keys”.
  3. Click on the “Add deploy key” button.
  4. Give the key a meaningful name, such as “Jenkins CI/CD Deploy Key”.
  5. Copy the public key from your Jenkins server and paste it into the “Key” field in GitHub.
  6. Make sure the “Allow write access” option is checked if you want Jenkins to be able to push changes to your repository.
  7. Click “Add key”.

Creating a Jenkins Job

Now that the Deploy Key is set up, you can create a Jenkins job to automate your CI/CD pipeline. To create a Jenkins job, follow these steps:

  1. Log in to your Jenkins server.
  2. Click on the “New Item” button.
  3. Give the job a name, such as “My GitHub Project CI/CD”.
  4. Select “Freestyle project” as the type of job.
  5. In the “Source Code Management” section, select “Git”.
  6. Enter the URL of your GitHub repository in the “Repository URL” field.
  7. Select “SSH” as the “Credentials” type.
  8. Select the Deploy Key that you set up earlier.
  9. In the “Build Triggers” section, select “GitHub hook trigger for GITScm polling”.
  10. In the “Build” section, add a build step to run your tests or build your application.
  11. Save the job.

Configuring Jenkins to Build on Push

You can configure Jenkins to automatically build your application whenever you push changes to your GitHub repository. To do this, follow these steps:

  1. Log in to your Jenkins server.
  2. Go to the job that you created earlier.
  3. Click on the “Configure” button.
  4. In the “Build Triggers” section, select “GitHub hook trigger for GITScm polling”.
  5. Save the job.

Conclusion

By setting up Jenkins CI/CD for GitHub using Deploy Keys, you can automate your software development processes and make them faster, more reliable, and easier to manage. The steps outlined in this article provide a simple and efficient way to get started with Jenkins and GitHub. By following these steps, you can start taking advantage of the many benefits of CI/CD and Jenkins right away.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.