---
title: "How To Create a Jenkins Build Job to Automate Web Deployments"
description: "Tired of manual deployment each time you update your code? Learn how to automate deployments by creating Jenkins build job in this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/jenkins-build-job/"
---

# How To Create a Jenkins Build Job to Automate Web Deployments

> Tired of manual deployment each time you update your code? Learn how to automate deployments by creating Jenkins build job in this step-by-step tutorial!

Source: https://adamtheautomator.com/jenkins-build-job/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Create a Jenkins Build Job to Automate Web Deployments](https://adamtheautomator.com/wp-content/uploads/2021/11/Create-a-Jenkins-Build-Job-to-Automate-Web-Deployments.jpg)

# Create a Jenkins Build Job to Automate Web Deployments

[![](https://secure.gravatar.com/avatar/d7af82363022947ce49ba2d0ec3b9470f7797b2541539ad2765a998a9c70c65c?s=192&d=mm&r=g)Ekekenta Clara](https://adamtheautomator.com/author/ekekenta-clara/)9 November 20217 min. read

Categories: [DevOps](/category/devops/)

Tags:[Jenkins](/tag/jenkins/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Creating a Jenkins Build Job](#creating-a-jenkins-build-job)
*   [Creating Credentials for a Jenkins Project](#creating-credentials-for-a-jenkins-project)
*   [Adding SSH Private Key to Jenkins Credentials](#adding-ssh-private-key-to-jenkins-credentials)
*   [Configuring Build Triggers and Post Build Actions](#configuring-build-triggers-and-post-build-actions)
*   [Conclusion](#conclusion)

Building and deploying an application can be a difficult task. Why not use a [Jenkins](https://www.jenkins.io/doc/) Build Job to automate the entire process? You concentrate on building while Jenkins handles code deployment.

In this tutorial, you will learn how to automate your code deployment using Jenkins to save time so that you can focus on other tasks simultaneously.

Ready? Time to dive in!

## Prerequisites

This tutorial houses hands-on demonstrations. If you’d like to follow along, be sure you have the following:

*   An Ubuntu System – This tutorial uses Ubuntu 20.04 for the demonstrations
*   A [GitHub account](https://github.com/join)
*   [OpenJDK version 1.8.0\_292](https://openjdk.java.net/install/)
*   [Jenkins version 2.303.1](https://www.jenkins.io/doc/book/installing/linux/#debianubuntu)
*   [Node.js version 14.17.6](https://nodejs.org/en/download/)
*   [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository) this [GitHub repository](https://github.com/Adam-the-Automator/webDeploy) – After forking, note the GitHub repository URL as you’ll need it later.

> _Although the repository shown in the below screenshots slightly differs from the one linked above, once forked, you will use a different repository URL as well._

Related:[How to Run Jenkins in Docker using Docker Compose with Volumes](https://adamtheautomator.com/jenkins-docker/)

## Creating a Jenkins Build Job

Jenkins is an open-source automation server that aids in the automation of a software development life cycle. This life cycle includes building, testing, and deploying, which facilitates continuous integration and continuous delivery.

In this demo, you’ll go through how to create a Jenkins build job. A build job is typically a configuration for autonomously running tasks for building/packaging software.

1.  Launch your favorite browser, navigate to http://localhost:8080/, and log in to your Jenkins dashboard. Port `8080` is the default port to access the Jenkins dashboard.

2\. On your Jenkins’ **Dashboard**, click on the **New Item** button in the left panel to initialize creating a build job. Doing so redirects the browser to a new job page.

![Creating a new Jenkins Job](https://adamtheautomator.com/wp-content/uploads/2021/11/image-104.png)

Creating a new Jenkins Job

3\. Next, enter a project name you prefer for the build job in the input field shown below. For this example, the project name is **webDeploy**.

Select the **Freestyle project** option to enable creating jobs, script post-build actions, and configure project [build triggers](https://blog.knoldus.com/jenkins-build-triggers/), then click **OK**. You will be redirected to the job configuration page that you’ll see in the next step.

![Creating a Jenkins project](https://adamtheautomator.com/wp-content/uploads/2021/11/image-105.png)

Creating a Jenkins project

4\. Click on the **General** tab, and check the **GitHub project** box to link a source code manager so that Jenkins will know where to pull your code. This demo uses Git as the source code manager for the sample project hosted on GitHub that you forked earlier. Paste the GitHub repository URL from your GitHub account to the **Project url** field below.

![](https://adamtheautomator.com/wp-content/uploads/2021/11/image-106.png)

Linking Jenkins to a source code manager

5\. Finally, click on the **Source Code Management** tab, then select **Git**, which is your source code manager.

Copy and paste this GitHub repository URL _(https://github.com/Claradev32/webDeploy.git)_ into the input field. Click on the **Save** button to save your current configurations.

![Linking Jenkins to Source Code Manager (Git)](https://adamtheautomator.com/wp-content/uploads/2021/11/image-107.png)

Linking Jenkins to Source Code Manager (Git)

## Creating Credentials for a Jenkins Project

Perhaps you prefer to keep your repository private, which is common for client projects. If so, you’ll need to create credentials to authorize Jenkins to clone your project from GitHub.

To create credentials for your Jenkins project, you must generate and add an SSH key first to your GitHub account:

1\. Open your Ubuntu terminal, and run the command below to generate an SSH key with [`ed25519`](https://ed25519.cr.yp.to/) as the key type. Replace `your_email@example.com` with your GitHub email address to add it as a comment to the SSH key you’ll generate.

```bash
ssh-keygen -t ed25519 -C "your_email@example.com"
```

2\. Save your public SSH key with the following:

*   Specify a save location for the SSH key and press **Enter**. If you don’t, the command saves the SSH key on a default location, as shown below.
*   Type in a secure passphrase for the SSH key, press **Enter** to confirm the passphrase, and you’ll see the output of your public SSH key.
*   Take note of the location of your generated SSH key as you’ll add it to your GitHub account in the following steps.

![Adding a Passphrase to the SSH key](https://adamtheautomator.com/wp-content/uploads/2021/11/image-108.png)

Adding a Passphrase to the SSH key

3\. Sign in to GitHub on your web browser and navigate to your Account Settings page.

4\. Click the **SSH and GPG keys** link on the left panel and then click on **New SSH Key**, as shown below, to configure your new SSH key.

![Creating a Github SSH key](https://adamtheautomator.com/wp-content/uploads/2021/11/image-109.png)

Creating a Github SSH key

5\. Finally, enter your preferred title for the SSH key. The title is only for internal documentation purposes. Paste your SSH key, from the previously saved file, in the **Key** input field, and click **Add SSH Key** to save the key.

> __Remember this is your public key and not your private key!__

![ Saving New SSH Key](https://adamtheautomator.com/wp-content/uploads/2021/11/image-110.png)

Saving New SSH Key

## Adding SSH Private Key to Jenkins Credentials

Now that you have created your SSH key pair to use as a Jenkins credential, you must also add your SSH private key to your Jenkins credentials to authorize Jenkins access to your GitHub repository. But first, take note of your GitHub repository’s SSH URL.

1\. Navigate to your GitHub repository page, click on **Code → SSH**, and click on the copy icon shown below to copy the SSH URL to the clipboard.

![Noting Down GitHub SSH URL](https://adamtheautomator.com/wp-content/uploads/2021/11/image-111.png)

Noting Down GitHub SSH URL

2\. Next, navigate to your [Jenkins dashboard](http://localhost:8080/), then click on **Manage Jenkins** to access your project’s settings page.

![Accessing Jenkins Settings](https://adamtheautomator.com/wp-content/uploads/2021/11/image-112.png)

Accessing Jenkins Settings

3\. Scroll down, then click on the **Manage Credentials** option under the **Security** section to view the list of your Jenkins credentials.

![Accessing Jenkins Credentials](https://adamtheautomator.com/wp-content/uploads/2021/11/image-113.png)

Accessing Jenkins Credentials

4\. Click **Jenkins** on the **Credentials** page shown below to access the “System” page where you can add new credentials.

![Accessing System Page to Add Credentials](https://adamtheautomator.com/wp-content/uploads/2021/11/image-114.png)

Accessing System Page to Add Credentials

5\. Now, on the **System** page, hover your mouse over the **Global credentials (unrestricted)** option to display the drop-down menu and click on the arrow down icon.

Click on **Add credentials** from the drop-down menu. The page redirects to a form where you’ll configure the new credentials shown in the next step.

![System Page](https://adamtheautomator.com/wp-content/uploads/2021/11/image-115.png)

System Page

6\. Select **SSH Username with private key on the first input field and** enter a project username in the **Username** field. For this example, the username is **CI/CD**.

> _In this case, the username is purely internal documentation and is not used for authentication._

![Setting a Username for Jenkins Global Credentials](https://adamtheautomator.com/wp-content/uploads/2021/11/image-116.png)

Setting a Username for Jenkins Global Credentials

7\. Run the command below to view your SSH Private key, changing the location to where your key is saved, as shown below (the key below is located in the home directory). Note your SSH Private key as you’ll add it to your Jenkins credentials in the next step.

```bash
cat ~/.ssh/id_ed25519
```

![Viewing Secret Key](https://adamtheautomator.com/wp-content/uploads/2021/11/image-117.png)

Viewing Secret Key

8\. Once you have noted your SSH Private key, go back to the **Global credentials (unrestricted)** page.

Enter the passphrase you set on the “Creating Credentials for a Jenkins Project” section (step two) to the **Passphrase** input field, and click **OK**. Doing so authorizes Jenkins access to your GitHub repository.

If you didn’t include a password while creating the SSH key, click **Enter directly** and click the **Add** button. Enter your SSH Private key into the **Key** input field, as shown below, and press the **OK** button to save the credentials.

![Adding GitHub SSH key to Jenkins Credentials](https://adamtheautomator.com/wp-content/uploads/2021/11/image.gif)

Adding GitHub SSH key to Jenkins Credentials

8\. Go back to your [Jenkins dashboard](http://localhost:8080/), hover your mouse to your project and click on the arrow down icon, then choose **Configure**, as shown below. The page redirects to your project’s configuration page.

![Configuring Jenkins Project](https://adamtheautomator.com/wp-content/uploads/2021/11/image-118.png)

Configuring Jenkins Project

10\. Finally, select the credentials username in the dropdown field (from step six of the “Adding Secret Key to Jenkins Credentials” section). Jenkins applies the [CID principle](https://blog.gds-gov.tech/that-ci-cd-thing-principles-implementation-tools-aa8e77f9a350) by default to ensure your project’s continuous integration and deployment.

![Connecting Jenkins to GitHub](https://adamtheautomator.com/wp-content/uploads/2021/11/image-119.png)

Connecting Jenkins to GitHub

## Configuring Build Triggers and Post Build Actions

You’ve now successfully created the skeleton of a build job. But if you regularly make changes to your project, will you have to redeploy each time manually? Why not set up build triggers? Build triggers automatically redeploy your project’s changes pushed to GitHub.

1\. On your projects configuration page, click on the **Build triggers tab,** and check the **GitHub hook trigger for GITScm polling** option. This option allows you to redeploy your project’s changes automatically.

![Configuring build triggers](https://adamtheautomator.com/wp-content/uploads/2021/11/image-120.png)

Configuring build triggers

2\. Click the **Build** tab, click on **Add build step**, and select **Execute shell** to create a script that will run whenever Jenkins downloads a new version of your code.

![Creating a Build Script ](https://adamtheautomator.com/wp-content/uploads/2021/11/image-121.png)

Creating a Build Script

> _The shell script you create is dependent on your development environment. If you’re on Windows, Windows will execute the script; the same is true for other operating systems._

3\. Type in the below shell commands, and click **Save** to save the build script. After saving the changes, the page redirects back to your project’s dashboard.

The commands below pull (`pull`) your code from your source code remote location (`origin master`) and with [NodeJS NPM install](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) (`npm install`) the necessary dependencies required to run your project. The commands execute each time you make a push request to your source code manager.

> _This particular project utilizes NodeJS for dependencies, but your particular project may not._

```bash
git pull origin master
npm install
```

![Adding Commands to the Automated Build Script](https://adamtheautomator.com/wp-content/uploads/2021/11/image-122.png)

Adding Commands to the Automated Build Script

4\. Now, on your project’s dashboard, click **Build Now** to run the build.

![Running the Build](https://adamtheautomator.com/wp-content/uploads/2021/11/image-123.png)

Running the Build

5\. Scroll down to the build history to see the build’s status. If the build was successful, you’ll see a similar output to the screenshot below.

![Viewing Successful Build](https://adamtheautomator.com/wp-content/uploads/2021/11/image-124.png)

Viewing Successful Build

If the build fails, you’ll see the output shown below.

![Failed build history](https://adamtheautomator.com/wp-content/uploads/2021/11/image-125.png)

Failed build history

6\. Next, scroll up and click on **Configure** to configure the project’s post-build actions.

![Configuring Project's Post Build Actions](https://adamtheautomator.com/wp-content/uploads/2021/11/image-126.png)

Configuring Project’s Post Build Actions

7\. Click on the **Post Build Actions** tab, then click on **Add post-build action** and choose **Git publisher**. The page expands the **Git Publisher** settings section (next step).

![Accessing Git Publisher Post-Build Action](https://adamtheautomator.com/wp-content/uploads/2021/11/image-127.png)

Accessing Git Publisher Post-Build Action

8\. Finally, enable the **Push Only If Build Succeeds** option and click the **Save** button to save the changes. Enabling this option tells Jenkins to deploy the code only when a build run succeeds.

![Adding Post-Build Actions](https://adamtheautomator.com/wp-content/uploads/2021/11/image-128.png)

Adding Post-Build Actions

## Conclusion

In this tutorial, you’ve gone through the process of connecting Jenkins to your source code management system. You’ve also created a build script that automatically runs when Jenkins downloads a new version of your code and set up build triggers to automate web deployments.

Now, why not save yourself some time by automating your application deployment with a Jenkins build job?

Related:[How to Set Up a New Jenkins Build Agent](https://adamtheautomator.com/jenkins-agent/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fjenkins-build-job%2F&text=Create%20a%20Jenkins%20Build%20Job%20to%20Automate%20Web%20Deployments)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fjenkins-build-job%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fjenkins-build-job%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/05/Focused-Job-Configuration-with-the-Jenkins-DSL-Plugin.jpg)

### [Focused Job Configuration with the Jenkins DSL Plugin](/jenkins-dsl/)

Learn the fundamentals of using the Jenkins DSL plugin to craft infrastructure as code and generate focused Jenkins jobs!

![](https://adamtheautomator.com/wp-content/uploads/2021/12/How-to-Create-a-Jenkins-CI-CD-Pipeline.jpg)

### [How to Create a Jenkins CI CD Pipeline](/jenkins-ci-cd/)

Learn how to implement a Jenkins CI CD pipeline to significantly improve and automate your software development process!

![](https://adamtheautomator.com/wp-content/uploads/2021/03/How-to-Set-Up-a-New-Jenkins-Build-Agent.jpg)

### [How to Set Up a New Jenkins Build Agent](/jenkins-agent/)

Add an additional Jenkins Agent Windows node to scale build job capacity and further automate your build environment!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
