Showing posts with label GITHUB. Show all posts
Showing posts with label GITHUB. Show all posts

Tuesday, August 29, 2023

Connect from Local Git to Github


GIT


Create a user git

chown -R git:git /home/git


su git


$ cd /home/git


$ mkdir .ssh


$ cd .ssh


$ git config --global user.name "git"


$ git config --global user.email "yashwanthsn@gmail.com"


$ git config --list


user.name=git
user.email=yashwanthsn@gmail.com


Create a repository on GITHUB: https://github.com/new
enter the details and click on create repository


Create a "automation" directory on local git

$ mkdir automation


$ cd automation


$ pwd
/home/git/automation


run git init command
Add SSH git link using git remote add origin command

git remote add origin git@github.com:yashwanthsn2020/automation.git


you can change this to https git link later using git remote set-url origin command

git remote set-url origin git@github.com:yashwanthsn2020/automation.git

Create a config file under $HOME/.ssh in local git

check on how to add SSH Keys from local Git to GITHUB repository -> Generate SSH Keys for Github GIT
Now check the branch and run git push command using git branch and git push commands
Now go to GITHUB -> https://github.com and click on automation repository

In my case the link is https://github.com/yashwanthsn2020/automation


You will be able to see the file that we pushed from local git to github

Integrate Jenkins with Github

 GIT and Jenkins


Install Git plugin and GitHub plugin on Jenkins, in my case the jenkins login url is http://localhost:8080

Click on Manage Jenkins -> Manage Plugins -> search for Git plugin and GitHub plugin and install it
Integrate Jenkins with Github:

Login to GitHub and get the Project and Repository URL. In my case

Project URL: https://github.com/yashwanthsn2020/automation/


Repository URL: https://github.com/yashwanthsn2020/automation.git


Create a new job in jenkins -> jenkins-git-integration -> Freestyle project -> click OK

On the General tab -> choose GitHub project and add the Project URL

Under Source Code Management -> choose Git and add Repository URL

Branches to build: by default it will be master branch, you can add other branches 

Under Build Triggers section I chose Build Periodically since my jenkins run on localhost. 

I.e, http://localhost:8080, we can not add a webhook from GitHub to jenkins for a localhost

If Jenkins is not on localhost, you can choose "GitHub hook trigger for GITScm polling"
Click on Save and -> Back to Dashboard -> choose the job -> Jenkins-git-integration -> click on Build Now

Here is the console output from Jenkins
If you choose GitHub hook trigger for GITScm polling under Build Triggers, then you have to login to GitHub -> Settings -> Webhooks -> Add webhook
Click on Add webhook