Jenkins: An introduction to jobs and projects

This guide will explain what a Jenkins job (or project) is and discuss the different types you may encounter. There are many types available, and it depends on the plugins that you have installed. First, however, this guide will discuss the main types that you will encounter.

What is a Jenkins job or project?

A Jenkins job is a sequential set of tasks that a user defines. For example, a job can fetch source code from version control, compile the code, run unit tests, and more.

Note that in Jenkins, the term “job” is synonymous with “project”. In addition, the number of job types depends on the plugins that you have installed. For example, a Maven Project/Job is only available If you installed the Maven plugin.

Let’s take a look at the main job types in Jenkins:

Freestyle project

This job type is the default project type and is the most flexible to configure.

Maven project

The Maven Project job type helps build Maven projects. However, Jenkins does not provide it as part of the core functionality. As such, it requires you to install the Maven Integration plugin.

Pipeline

A pipeline is a way of defining your entire build process using code in the form of a Jenkinsfile.

Here is an example from Jenkins:

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }
}

Multi-branch pipeline

A multi-branch pipeline is an extension of a Pipeline Job. However, it has a way of automatically creating Jenkins pipelines based on source control branches. Jenkins can then automatically discover new branches in the source control, and it can also automatically create a pipeline for that branch.

Here is an example from Jenkins:

pipeline {
    agent {
        docker {
            image 'node:6-alpine'
            args '-p 3000:3000 -p 5000:5000' 
        }
    }
    environment {
        CI = 'true'
    }
    stages {
        stage('Build') {
            steps {
                sh 'npm install'
            }
        }
        stage('Test') {
            steps {
                sh './jenkins/scripts/test.sh'
            }
        }
    }
}

Create a Jenkins job

You can create a new Jenkins job by clicking Jenkins > New Item from the side navigation bar.

Jenkins will then provide you with a wizard that allows you to configure your Jenkins job.

Organize jobs

Jenkins allows you to organize jobs using Folders and Views, so you can logically separate jobs. You can also create new views and set them as default views. For further information, please see the documentation for the Folders plugin.

Jenkins job components

A Jenkins job consists of the following components:

Global project options

First, the global project options section allows you to set general project settings.

You can for amongst other:

  • Discard old builds where you can choose the days to keep a build, max number of builds and much more.
  • Define the GitHub project the build should use
  • Throttle builds
  • Disable the project
  • Execute concurrent builds
  • Restrict where this project can be run

Source code management

Then the source code management section allows you to specify the version control repository for your source code.

Jenkins supports, among others:

  • None
  • CVS
  • CVS Projectset
  • Git
  • Subversion

Build triggers

Next, we have the build triggers section. This section allows you to specify what will trigger your build.

You can either:

  • Trigger a job manually.
  • Build it periodically using a creon-like syntax.
  • Start a build once another project has completed.
  • Poll a source source code version control.
  • Build based on a web-hook.

Build environment

Then we have the build environment section that allows you to specify additional options for your builds.

These options include amongst other:

  • Cleaning up the workspace prior to starting a build
  • Setting up the environment variables
  • Aborting stuck builds
  • Adding log timestamps

Build

The build section allows you actually to add the build steps. Here you can build source code, do tests, check code coverage, and much more. You can also run scripts. And, not surprisingly, you can also run code on remote machines.

Post-build actions

Finally, the post-built actions notify developers, publish test reports, archive build artifacts, trigger other build projects, etc.

You may also be interested in

What are the types of Jenkins Jobs | Jenkins A to Z from ServerGyan | Part-2


About the Authors

Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee



About Anto Online

Having started his career in 1999 as a Desktop Support Engineer, Anto soon changed paths and became a developer. After several years of development experience, he transitioned into a consultant. As an enterprise application consultant for a leading SaaS software provider, Anto specializes in AWS's serverless technologies. By day, Anto focuses on helping customers leverage the power of serverless technologies. By night, he indulges his passion for cloud computing by playing with Python and trying out things that are currently beyond the scope of his work. Sometimes Anto needs help as there are not enough hours at night. So Anto relies on a team of fellow Cloud enthusiasts to help him out. Each one is a Cloud expert in their own right, and Anto takes great pride in helping them learn and grow.

View all posts by Anto Online →

Leave a Reply

Your email address will not be published.