Create CI/CD pipeline using jenkins
Tags: github, git, jenkins, devops
Published: 2021-08-28 05:16:42

## For all the people who do not know what jenkins is , let me explain it to you

> Jenkins is a CI/CD tool that you can use on any project of yours or your companies to make your lives a little easier .
What it does for you is a whole lot of things 
just for example 
* lets just say you want that whenever a team member pushes anything to a specific branch of your project all unit and integration tests should run first hand .

You can do that with jenkins .

* You want that everytime a push is made to the repo it gets re build , jenkins got you .

CI/CD is very powerful tool for any developer to have in this era and there are many tools that let you do this , **Jenkins** being one of them.

Ok , so now you understood what jenkins is , lets just use it in our project and try to create a pipeline.
* Go ahead and download [jenkins](https://www.jenkins.io/download/).
* Once downloaded go to the directory using your terminal 
* once inside the terminal , type the command
`Java -jar jenkins.war`
* This will start the jenkins on *localhost:8080* and will also give you the password autogenerated 
![Jenkins password ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zrkm4m0u4a1e2gl4xlt.png)
* copy this password and go to *localhost:8080* and you will be greeted by this screen
![unlock jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6h8jumjb92kqj8bg9f1u.jpeg)
* Use the password you just copied from the terminal here
* If you want you can also create a user (we are not going to do that here).
* so every thing set up this page will appear in front of you(you wont be having the multitesting in front of you )
![jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3g001zdd8pvcvnwqxn1h.png)
* Here what you can do is click on new item and this screen will be visible to you
![new item jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ueo90y82bdzhud0oz2ag.png)
* Here give your project a name and click on multipipeline and click ok
* You will be greeted with a new screen here , that has a bunch of options to configure but what we want is we want to hook it up with our github repo . So first of all create a create a new github repo and make sure you create a file namely `Jenkinsfile` in it .
* Inside that file paste this code 
```
pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building..'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
            }
        }
    }
}
```

* Once this is done take the https github url from the clone like this 
![github url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6prrla1b42zdpdmg06lv.png)
* Ok perfect , now go back to your jenkins local host 
and from all those options find Branches > Click on Add Source and click on git

![git integration in jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4jl13ldshjykqsrqhyc.png)
* Now paste your github url that you copied over here like this 
![github integration jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cm7ot7cvawrllpzhr4qv.png)

* perfect 👌  , now click on save .
> What it will do is it will scan your branches by itself and run the tests for you .
* By this point of time you are basically done but just to make it a little interesting what you can do is push anything to your code base and then come to your github and click on scan multibranch pipeline now .
This will force it to rescan the code and in any branch where it see the change it will re build that branch (On a real life scenario you dont have to do it manually , it will do it yourself via a github hook that will be made inside of the github , but since its on localhost git hub wont allow that )

Ok perfect you are done and can go ahead and learn more about the code in the jenkins file [here](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/) .
You can do a lot of cool stuff with it , run cron jobs , run tests etc which is outside of the scope of this tutorial.

Ok , i hope you guys have learnt anything new from this tutorial .
Feel free to reach me at my [Linkedin]('https://www.linkedin.com/in/junaid-shah-ba2910a9/')

Want to encourage me to create posts like this more 
[Buy me a coffee]('https://www.buymeacoffee.com/jshahcodes')