# Build Jenkins First Job

Click on **create new jobs**:

<img src="https://cdn.guru99.com/images/1/091318_0440_JenkinsGitH6.png" alt="" data-size="original">

Enter the item name, select job type and click **OK**. We shall create a **Freestyle project** as an example.

![](https://2593464885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3DMI85ymmo2BqduKTK9p%2Fuploads%2F7PM13MKiZ25ypnisRhQ8%2Fimage.png?alt=media\&token=1b1617a7-5046-4ab9-929c-34a8199fbed4)

Once you click **OK,** the page will be redirected to its project form. Here you will need to enter the project information:

&#x20;You will see a **Git** option under **Source Code Management** if your Git plugin has been installed in Jenkins:

![](https://cdn.guru99.com/images/1/091318_0440_JenkinsGitH9.png)

Enter the **Git repository URL** to pull the code from GitHub.

\
Scroll Down and click on Add Build Step >> Invoke top-level Maven Targets:

![](https://2593464885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3DMI85ymmo2BqduKTK9p%2Fuploads%2FYagVgdb7usaoreCbeEFw%2Fimage.png?alt=media\&token=d4b2de2b-bffb-4dd1-9e94-749e4e8e9fae)&#x20;

In the Goal section type " `test install` " maven command this command is used to test and create a **build file**.&#x20;

APPLY and SAVE.

Now we need to provide paths for JAVA, Maven and Git to jenkins:

1. Go to Jenkins Dashboard
2. Manage Jenkins >> Global Tool Configuration
3. You will see window like this&#x20;
4. ![](https://2593464885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3DMI85ymmo2BqduKTK9p%2Fuploads%2FwR2vlB4X243iIbPYNFUv%2Fimage.png?alt=media\&token=877534b3-8342-4993-99ee-bc7d17454d6e)&#x20;
5. Here we have to provide path for JDK, Git and Maven(scroll down )
6. Click on **ADD JDK** >> **untick** install automatically (because we have already downloaded it we just need to give the path) Login to EC2 shell and type the following commands

```
echo $JAVA_HOME //copy the path and paste in JAVA_HOME
which git //paste the git path 
echo $MAVEN_HOME //copy and paste in Maven section
```

(Note down the name of Maven you entered you have to change it in Build step section where we wrote "test install" command)&#x20;

Apply & save

### Lets Build&#x20;

Before we click build now we need to do small task. Navigate to JENKINS Dashboard and select your job >> Configure >> scroll down >> Select the Maven name you entered in previous secton

![](https://2593464885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3DMI85ymmo2BqduKTK9p%2Fuploads%2FzWmuTiRVmmsYcpYodHSO%2Fimage.png?alt=media\&token=7f3d08d7-a080-408e-88e1-00636afbd171) Apply and Save

Now click on **Build now** and see the console output&#x20;

![](https://2593464885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3DMI85ymmo2BqduKTK9p%2Fuploads%2FkAlWnJZXTVS4XWRnawz6%2Fimage.png?alt=media\&token=71e37d0e-c8e6-43aa-9f8e-792769185d5f)

If you Success. Congratulations, Jenkins has successfully created **`.war`** file we can see the file in the destination provided in console out lets check it.

![](https://2593464885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3DMI85ymmo2BqduKTK9p%2Fuploads%2Fg0WuLjzvU0OYEZ9d2BMs%2Fimage.png?alt=media\&token=56b61a32-d912-4410-a9cd-7bc102dbcf1f)

As you can see we have the webapp.war (build file) Now we need to deploy this on Tomcat Server which we will host on another EC2 server with Docker Containers :whale:
