# DevOps Tools (Jenkins Installtion and Small demo to Access Code from Github) ###### tags: `Devops` `K8s` `Docker` `Jenkins` `Ansible` `Terraform` ## Jenkins ### CI/CD Pipelines Project: ![](https://i.imgur.com/A7nbLZ1.png) ### Jenkins Installtion Linux 20.04 #### Step 1: Installing java jdk ```javascript= # sudo apt update # sudo apt install default-jre # sudo apt install default-jdk ``` #### Step 2: Installing Jenkins (Non-root user) ```javascript= # sudo apt update # wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - # sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' # sudo apt update # sudo apt install jenkins ``` #### Step 3 Starting Jenkins ```javascript= # sudo systemctl start jenkins # sudo systemctl status jenkins ``` ![](https://i.imgur.com/mJuuFdp.png) #### Step 4 Opening Firewall ```javascript= # sudo apt-get install openssh-server # sudo ufw allow OpenSSH # sudo ufw enable # sudo ufw allow 8080 # sudo ufw status ``` ![](https://i.imgur.com/LB0GrDZ.png) #### Step 5 Setting up Jenkins ![](https://i.imgur.com/K75Euxm.png) In the terminal window, use the cat command to display the password: ```javascript= # sudo cat /var/lib/jenkins/secrets/initialAdminPassword ``` copy the password: ![](https://i.imgur.com/Qq4h52v.png) paste the copied password in the administrator password box and click on continue: ![](https://i.imgur.com/Hyh6S2z.png) Install Suggested Plugins: ![](https://i.imgur.com/3uhi1Qq.png) ![](https://i.imgur.com/MethlDW.png) ![](https://i.imgur.com/MdU9GAY.png) ![](https://i.imgur.com/VjTIf5D.png) ![](https://i.imgur.com/zn85Nhr.png) ![](https://i.imgur.com/gaXwAMn.png) #### How to connect Git Repository in Jenkins (GitHub) Manage Jenkins -> Manage Plugins ![](https://i.imgur.com/L9fAHUk.png) check the installed plugin and search the git. If not installed then go to available plugin in Install git and others plugins you need. ![](https://i.imgur.com/ZRph3m6.png) create a new project ![](https://i.imgur.com/gaXwAMn.png) Enter an item name and choose the freestyle project for now and click ok. ![](https://i.imgur.com/UBt3dK0.png) Now you can see this page with many options. Now you can check options you need or not as per your projects needs: ![](https://i.imgur.com/BnP1KzT.png) Under the source management you can find the git because you add pulgin, If you cant find the git then go to manage plugins and install ![](https://i.imgur.com/pEevUeP.png) Now open the browser go to github.com and signup, but I have already my account so I can use that. ![](https://i.imgur.com/LxdtU2j.jpg) login to github account. create a new repo ![](https://i.imgur.com/FBKIVIP.png) Write the repo name and keep it public but its depends on you and click on creat repository. ![](https://i.imgur.com/QqeRg4o.png) As of now its is empty and see like this click on the create new file. ![](https://i.imgur.com/09vCuxC.png) Write the name of the file and some text for demo and commit. ![](https://i.imgur.com/PME1Pqh.png) The File is commited and looks like this. ![](https://i.imgur.com/59PZ7cF.png) Now we can access this file from jenkins server. In order to do that first need to add credentials ![](https://i.imgur.com/i9OhJkN.png) ![](https://i.imgur.com/dpwz5us.png) ![](https://i.imgur.com/OGlPYKa.png) ![](https://i.imgur.com/wl1t0O9.png) ![](https://i.imgur.com/cbmfa9y.png) ![](https://i.imgur.com/mGkH36M.png) Now you can go to add github repo in jenkins ![](https://i.imgur.com/hM1M5sD.png) But if you can find this error ***Failed to connect to repository : Error performing command: git ls-remote -h https://github.com/sohailanjum97/JenkinsStudy HEAD*** see this https://hackmd.io/lma1usiPSCuieZaPUc3GdA Now The last step is to build the job ![](https://i.imgur.com/proBFBt.png) ![](https://i.imgur.com/H34qgkr.png) check the lg click on any build. ![](https://i.imgur.com/Rd1Jj5N.png)