DEV Community

TheBadCoder
TheBadCoder

Posted on

Jenkins: Configure a job with remote git repository

Pr-requisites: You should have basic Jenkins job creation idea, if you don't, need not to worry a little, I have a boiler plate for you! Jenkins: Create a simple build job

So without wasting your precious time I will straight away start with modifying an existing Jenkins job to use git repository instead of local repository to perform a build execution.

Configure GitHub credentials

Pr-requisite- GitHub plugin should be installed, if you have installed the recommended plugins at the time of Jenkins setup, then you already have it.

Manage Jenkins

From Jenkins dashboard go to Manage Jenkins
Manage Jenkins

Stores scoped to Jenkins

Select the Jenkins store from the given list of stores, there would be only one generally so it wouldn't be difficult to find it.
Select Jenkins Store

System credentials

Select Global credentials from the list of system credentials, again there would be only one mostly.
Global Credentials

Add Credentials

On the left hand side you will have an option/menu to add new credentials, so that's the way for us to actually add our GitHub credentials.
Add Credentials Menu

Configure User

Here we need to provide few things and again we will go with the basic method here.

  • Kind => Username and Password (there are other options too)
  • Scope => Global
  • Username => Actual GitHub Username
  • Password => Actual GitHub Password

Once everything is provided click ok button to complete the process.
Configure GitHub User

Now that we are done with the git user configuration, lets go to the actual action by which we can clone the git repository to the build machine and do the further build actions.

Edit the job

Let's open the existing job that we want to configure to clone the git repository and click on Configure menu/option.

  • From General section uncheck use custom workspace configuration(not for new job creation)

Source code management

  • Choose Git option, it will uncover hidden configuration properties.
  • Repository URL- Get the repository URL from the GitHub which is of type HTTPS(this is the same place where you find the URL to clone the repository)
  • Credentials - Here we will be able to select the username and password pair that we configured in earlier steps. Git Configurations

Apply and save the changes to the job and we are all set to shoot the next build and see the effect taking place for the source code management section.
Go ahead and build the job again and checkout the console logs if the git repository is actually getting cloned and worked up on.

Hope this helps, the comments and suggestions are always welcome!

Top comments (0)