Updated: Sep 1, 2020
Normally when we have a few repositories, we add them manually to Jenkins but this is not the best way. Don’t you agree? If we have a lot of repositories, we don’t want to add every single repository manually.
Then we will want that Jenkins should auto detect new repositories.
Now what will happen is whenever a developer will create a new repository for a new (micro) service , add a Jenkinsfile, and the project will automatically be built in jenkins.
To achieve this GitHub branch source plugin will scan all the branches and repositories in a github organizations and build them via Jenkins Pipeline.
Let' see how it is done.
Login to Jenkins console -- Go to Manage Jenkins -- Manage Plugins --
Now go to jenkins console -- Create new item -- Select GitHub Organization
Now we need to provide details like display name and most important the credentials for github.
To generate the credentials, login to github -- Go to settings -- Developer Settings -- Go to Personal Access tokens ( and create one)
Provide the credentials and for the sake of convenience, we will change the scan interval to 1 minute.
When we will save and apply, jenkins will scan the github account and detect all the repositories and if it finds a Jenkinsfile in the root folder, will trigger a build automatically.
To demonstrate the same we will use an example of java project . The deployment will be container based so create a directory on the jenkins machine.
[root@ip-172-31-27-84 ~]# mkdir -p /var/lib/jenkins/.gradle [root@ip-172-31-27-84 ~]# chown -R jenkins:jenkins /var/lib/jenkins/.gradle
Source code for demo is available at here
git clone https://github.com/linuxadvise/gradle-js-demo.git
As soon as we commit this code in to the repo, it will be scanned and auto detected and build will trigger automatically.
Similar type of plugins are available for git lab and bit bucket as well. We can use any of them as per our requirement.
Hope this was helpful. Thanks for reading.