Jenkins “job configuration” streamlined

Arati AK Bhandare
6 min readJan 31, 2023

--

This article will explain what a Jenkins job (or project) is, we will also discuss the different types of jobs you may encounter. (There are many types available, apart from what we will discuss as it depends on the plugins that you have installed.)

Let’s begin exploring,

What is Job?

  • 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.
  • Jobs are the heart of Jenkins’s build process.
  • A job is a runnable task that Jenkins controls to achieve a required objective.

Jenkins Jobs are a given set of tasks that runs sequentially as defined by the user. in short, any automation implemented in Jenkins is a Jenkins Job.

Type of jobs

Jobs types to choose from Jenkins Interface
  • FreeStyle project — It lets you freely (most flexible) control the way Jenkins manages tasks that are to be automated.
  • Pipeline — Useful for complex jobs, for eg: it can run build steps in parallel, use logic to skip steps, even use different compute platforms for different steps.
  • Multi-configuration — It is useful when you have multiple jobs doing same thing for different combinations of parameters, instead of having many jobs for each set of parameters.
  • GitHub Organisation & Multi-branch pipeline — Used for working with code repos. GitHub Organisation scans GitHub repo for files that Jenkins uses to configure jobs automatically. Multi-branch pipeline is used to configure jobs for different branches from same repo.
  • Folders — Jenkins uses it to group things together.

Job Configurations

Let’s look into detail of how to configure Jenkins job.

General

In “Advanced” option you can choose number of days “artifacts” will be kept.
  • Description — You can add free text that describes job.
  • Discard old builds
    -
    Jenkins keeps record of all builds and files generated by the build, including logs and artifacts (useful to review job history)
    -
    These files take up space on server.
    - We can manage space by keeping old builds only for certain time or,
    - Only keep max. number of builds.
    - We can also use both above methods, so we have plenty of space on server.

SourceCode Management

  • It controls the way Jenkins interacts with code stored in Git repo.
  • Select Git option & enter repo url, credentials & branches to checkout here.
  • We can use Jenkins as key for integration test and deployment tool for code in repos. (Jenkins allows you to pull code from outside of job configuration into workspace where job runs)
  • Default branch is “master”. You will have to specify “main” branch as in case of modern repos, that is generally the name of branch else job will fail.

Build Triggers

Jenkins gives plenty of ways as to how your job can started (triggered)

  • Manual — Default method. No configuration needed.
  • Trigger builds remotely
    - Processes outside of Jenkins, trigger the job by accessing the url through Jenkins Web API
    - You need to define auth token that remote process needs to include in url. It keeps job secure, in case url in exposed.
  • Build after other projects are built
    - This lets Jenkins start jobs immediately after other jobs are completed.
    - Ideal when you have series of jobs depending on each other.
Trigger builds remotely & Build after other settings
  • Build periodically
    - Used for jobs that are run hourly, daily weekly and so on
    - Field where you specify “schedule” should be cron format.Precisely telling Jenkins when to run the job.
  • GitHub hook trigger for GitScm polling
    - Useful for GitHub projects
    - Allows Jenkins to start job based on activities in GitHub like release, tags or other types of commits.
    - Here you can setup tight relationship between GitHub & Jenkins know as “continuous integration”. Every GitHub change Jenkins gets notified by web hook, and then take some action.
Build periodically, GitHub Hook & Poll SCM configurations
  • Poll SCM
    - Not as efficient as GitHub.
    - Jenkins checks repo on a schedule and looks for changes
    - Because Jenkins keep checking, system running Jenkins will unnecessarily use resources.

Build Environment

Gives control over space where the job would run and steps to take when job is running.

  • Delete workspace before the build starts
    - cleanup before job gets started
    - When a job runs it uses specific directory called workspace. Files created by job are stored in workspace when job runs.
    - In this setting Jenkins will remove existing and create a new workspace.
    - Advance option provides facility to select folders that are to be deleted and as a safeguard a parameter that is to be checked before deleting.
  • Use secret text(s) or file(s)
    - useful for injecting secretes into job at runtime
    - Here you can specify username, password, certificates or other sensitive info and variables are the files that will hold the secrets when job is run.
    - Secrets are stored as Jenkins credentials created and stored outside of job before they can be used.
  • Abort build if stuck
    - Stops stuck jobs from running in infinite loop.
    - You can specify amount of time job runs
    - Or deadline for job to finish
    - You can abort stuck job or you can fail build and update build description
  • Add timestamps to Console Output
    - Log for build is updated as job runs. This setting gives more detail, by adding timestamps to each log entry.

Skipping Gradle and Ant settings as they are not generalised and are specifically set only if these 2 plugins are being used in Jenkins setup

Build

In this section you will tell Jenkins to do something very specific related to your project.

  • Each action that Jenkins takes is called build step.
Add Build Step
  • ‘Execute Windows batch command’ is for Jenkins setup on windows server and ‘Execute shell’ is for other OS. There are steps for Ant, Gradle & Maven as well if you are working on JAVA .
  • We can have more than 1 build steps.
  • You reorder build steps by dragging and drop build steps
New build step added

Post-build Actions

  • Gives you additional steps to take before entire build wraps up
  • The post-built actions notify developers via email, publish test reports, archive build artifacts, trigger other build projects, etc.
  • We can have more than 1 post-build actions.
  • You reorder post-build steps by dragging and drop.
Blue question marks on right are easy access links to help section

Conclusion

With the detailed explanation above you can now build Jenkins Jobs from scratch comfortably.

Use the concepts discussed and try building Jenkins jobs yourself and experiment with new things. As a one-step forward, I would suggest you start building multiple jobs, or maybe creating a pipeline will be a great move. #happycoding

--

--