Jenkins: Configure a job with remote git repository
Tags: jenkins, beginners, devops, productivity
Published: 2022-06-06 07:38:32

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](https://dev.to/thebadcoder/jenkins-create-a-simple-build-job-38bb) 

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uh2nbky5oysz2f0wcbdb.png)
 
### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6900giq8q07gqr7vico.png)

### System credentials
Select Global credentials from the list of system credentials, again there would be only one mostly.
![Global Credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnp02mkrlcqhmwd66cn2.png)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dln880umpvjfwaky499t.png)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rj41rq85morqbletxsna.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gakhpxhvbjdh09gj58g.png)

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!