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

About Anto Online

Anto, a seasoned technologist with over two decades of experience, has traversed the tech landscape from Desktop Support Engineer to enterprise application consultant, specializing in AWS serverless technologies. He guides clients in leveraging serverless solutions while passionately exploring cutting-edge cloud concepts beyond his daily work. Anto's dedication to continuous learning, experimentation, and collaboration makes him a true inspiration, igniting others' interest in the transformative power of cloud computing.

View all posts by Anto Online

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.