Reputation: 1
There are multiple approaches in integrating Jenkins with GitHub
Approach 1) Enable ssh communication between GitHub and Jenkins by copying public key file generated in Jenkins to GitHub account. This is one time task.
For any pipeline take any GitHub url(say ssh://[email protected]/account/repo.git
) and add using Github plugin for that respective pipeline cocnfiguration
So, Jenkins file just need to have checkout SCM
to checkout
Approach 2) Enable https communication by adding webhook for every new repo by generating token and enable https comunication between GitHub and Jenkins. But this approach should be repeated for every new repo created in GitHub.
We are using GitHub repo... in production
Which is the best practice of GitHub integration with Jenkins in production?
Upvotes: 1
Views: 860
Reputation: 4203
Both are basically two different things.
The first approach lets you set up credentials to checkout and push source code to GitHub using Jenkins. The second approach lets you set up automated build triggers when a change is detected in the repository.
In summary, the first is mandatory for a build to get the source code, while the second is optional as you can trigger builds manually as well, although automated triggers on code push are inherent to continuous integration. Also, you need not add webhooks individually for every repository. Rather, add it once at the organization level to have all the repositories in that organization covered including any new additions.
Upvotes: 1
Reputation: 1323045
Unless you are talking about an on-premise GitHub Enterprise, you also have an alternative approach with GitHub Action.
appleboy/jenkins-action
, a GitHub Action that trigger Jenkins jobs.That is:
name: trigger jenkins job
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: trigger single Job
uses: appleboy/jenkins-action@master
with:
url: "http://example.com"
user: "example"
token: ${{ secrets.TOKEN }}
job: "foobar"
Upvotes: 1