In Your First Jenkins Job you created orders-api-build using only three sections of its configuration, and in the previous lesson you learned to find your way around the interface. Now it is time to master the job as a tool: which types of items you can create in Jenkins and when to use each one, what the Freestyle project configuration options you have skipped so far actually mean, how to chain jobs so that one triggers another, and how to manage their lifecycle (copy, rename, disable, delete, abort). By the end, orders-api-build will be configured more robustly and will automatically trigger a second job, orders-api-smoke, which will run a smoke check on the generated .jar. That chaining will also show you the limits of this approach, which is what motivates pipelines.

The Item Types in New Item

Click New Item on the Dashboard. Jenkins asks you for a name and a type. These are the types you will see with the suggested plugins installed:

Type What it is When to use it Where it is covered
Freestyle project A job configured through forms: source code, steps and post-build actions Simple tasks, maintenance scripts, learning This lesson
Pipeline A job whose process is defined as code (a Groovy script with stages) Today's standard for building, testing and deploying Understanding Jenkins Pipelines and module 3
Multibranch Pipeline Automatically creates a pipeline for each branch (and pull request) of a repository that contains a Jenkinsfile Projects with feature branches and code review Multibranch Pipelines
Folder A container that groups jobs (and other folders) with its own namespace Organizing by team or product, delegating permissions This lesson
Organization Folder Discovers every repository in an organization (on GitHub, for example) and creates a Multibranch Pipeline for each one that has a Jenkinsfile Organizations with many similar repositories Integrating with Version Control Systems

If you have the Matrix Project plugin installed, you will also see Multi-configuration project, which runs the same job with combinations of values (for example, several Java versions). Today that need is better met with pipeline matrices, which you will see in Parallel Execution and Matrices.

At the bottom of the New Item page there is also a Copy from field: it lets you create the item as a copy of an existing one. You will use it further on.

Anatomy of a Freestyle Project Configuration

Open orders-api-build and click Configure. The page is divided into sections, which you can also reach from the page's own side menu:

Section Answers the question…
General What is this job and how does it behave?
Source Code Management Where does the code come from?
Triggers When does it start on its own? (Build Triggers in earlier versions)
Environment What preparation does the build need? (Build Environment in earlier versions)
Build Steps What runs?
Post-build Actions What is done with the result?

Almost every option has a ? icon to its right that expands its help text. Use it freely: Jenkins' built-in help is very thorough. We will leave Triggers for the next lesson.

General: Job Options

Besides Description, which you have already filled in, the General section contains several checkboxes. These are the most important ones:

Option What it does In the course
Discard old builds Retention policy: how many builds and artifacts to keep Configured in Workspaces, Artifacts and Build History
This project is parameterized Lets you ask for values when starting the build Configured in Parameters, Triggers and Build Scheduling
Execute concurrent builds if necessary Allows several builds of the same job to run at once We leave it disabled
Restrict where this project can be run Limits the nodes it can run on, using a label expression Conceptual until Managing Jenkins Nodes and Agents

Execute Concurrent Builds If Necessary

By default, if you start a build while another build of the same job is running, the second one waits in the queue until the first one finishes. If you enable this option, both will run at the same time, each in its own directory (the second in a workspace with the @2 suffix, as you saw in the architecture lesson).

Why do we leave it disabled in orders-api-build?

  • Two simultaneous builds would compete for the same built-in node resources and for the Maven cache in /var/jenkins_home/.m2.
  • In a job that builds a single branch, the most recent build is the one that matters: running builds of consecutive commits in parallel rarely adds value.

It makes sense to enable it for long, heavily used jobs whose builds are independent of each other, as long as there are enough executors.

Restrict Where This Project Can Be Run

When you enable it, the Label Expression field appears, where you enter a label expression like the ones in the architecture lesson (linux, linux && docker, etc.). Below it, Jenkins shows in real time how many nodes match it.

Try it without saving: type built-in (the label Jenkins automatically assigns to the built-in node) and you will see a message like Label built-in matches 1 node. Now type linux: Jenkins will warn you that no node has that label. If you saved it like this, builds would wait indefinitely in the queue with the message There are no nodes with the label 'linux'. Uncheck the option before leaving: we will use it for real once the linux-agent-01 agent exists.

Advanced Options

Under the Advanced button in the General section there are more options. For now it is enough to know they exist:

  • Quiet period: seconds to wait before starting a build (explained in 02-03).
  • Retry Count: checkout retries if downloading the code fails.
  • Block build when upstream project is building / downstream: prevent this job from running while a related job is running.
  • Use custom workspace: sets a working directory other than the usual one. Not recommended except in very specific cases.
  • Display Name: a display name different from the actual name (the actual name is still used in the URL).

Source Code Management: Branches and Additional Behaviors

Branches to Build

In the previous lesson you used */main. The Branch Specifier field accepts other forms:

Value Meaning
*/main The main branch of any remote
origin/main The main branch of the origin remote
*/release-* Any branch starting with release-
refs/tags/v1.0.0 A specific tag
(empty) or ** Any branch (Jenkins builds whichever has changes)

You can add several specifiers with Add Branch. Be careful: a Freestyle project that builds several branches mixes all their builds into a single history, which gets confusing. For working with several branches there is the Multibranch Pipeline type, which you will see in module 4.

Additional Behaviours

By clicking Add under Additional Behaviours you can change how Git fetches the code. The most common ones:

Behavior What it does When to use it
Clean before checkout Runs git clean -fdx before updating the code: deletes everything that is not under version control (including target/) To guarantee that every build starts from a clean state
Clean after checkout The same, but after updating the code Equivalent in practice; pick one
Wipe out repository & force clone Deletes the entire workspace and clones again Corrupted repository; slower
Check out to a sub-directory Checks out the code into a subdirectory of the workspace Jobs that combine several repositories
Advanced clone behaviours Shallow clone, depth, no tags… Very large repositories

Let's add Clean before checkout to orders-api-build. Why? Without it, the workspace keeps generated files between builds (for example, the target/ directory from the previous build). Maven usually handles this well, but if a class is deleted from the repository, its old .class file may remain in target/ and mask errors. With git clean -fdx:

  • -f (force): actually deletes the files.
  • -d: includes directories.
  • -x: also includes files ignored by .gitignore, such as target/.

The Maven cache is not affected, because it lives in /var/jenkins_home/.m2, outside the workspace. Builds will still be fast.

Environment: Preparing the Build Environment

The Environment section contains options that act around the build steps. Several of them come from plugins included in the suggested plugins; if you do not see them, you will learn how to install them in Using Jenkins Plugins.

Option Plugin that provides it What it does
Delete workspace before build starts Workspace Cleanup Deletes the entire workspace before starting
Add timestamps to the Console Output Timestamper Adds the time to every console line
Terminate a build if it's stuck Build Timeout Aborts or fails a build that exceeds a time limit
Use secret text(s) or file(s) Credentials Binding Injects credentials as variables (covered in 04-04)

Delete Workspace Before Build Starts vs. Clean Before Checkout

Both options aim for clean builds, but they are not the same:

Clean before checkout Delete workspace before build starts
What it deletes Only untracked files The whole workspace, including the cloned repository
Cost Low: Git only fetches what is new High: the repository has to be cloned again on every build
Usable without Git No Yes

For orders-api-build, Clean before checkout is enough. You will look at workspace cleanup in more depth in Workspaces, Artifacts and Build History.

Add Timestamps to the Console Output

Stamps every console line with the time it was written, which lets you see which part of the build is slow. We introduce it here because it lives in this section, but you will enable it in Using Jenkins Plugins, when you study the Timestamper plugin that provides it.

Terminate a Build If It's Stuck

A hung build (a test waiting on a network that never responds, a process waiting for keyboard input…) occupies an executor indefinitely. This option puts a cap on it. Configure it in orders-api-build:

  1. Check Terminate a build if it's stuck.
  2. Under Time-out strategy, choose Absolute and enter 15 in Timeout minutes.
  3. Under Time-out actions, keep (or add) Abort the build.

The available strategies:

Strategy Criterion
Absolute A fixed number of minutes
Elastic A percentage of the average duration of recent builds
Likely stuck When the build takes much longer than usual
No Activity When the console writes nothing for a period of time
Deadline At a specific time of day

Our build takes less than a minute; 15 minutes is a generous margin that will only be reached if something goes really wrong. If it happens, the console will end with:

Build timed out (after 15 minutes). Marking the build as aborted.
Build was aborted
Finished: ABORTED

Build Steps: Multiple Steps and the Maven Wrapper

A Freestyle project can have several steps, which run in order. If one fails, the following steps do not run and the build ends in FAILURE. Splitting the work into steps makes the configuration easier to read. Reorganize the steps of orders-api-build like this:

Step 1 (Execute shell): information and preparation.

echo "Build ${BUILD_NUMBER} of job ${JOB_NAME}"
git log -1 --oneline
chmod +x mvnw
  • echo "Build ${BUILD_NUMBER} of job ${JOB_NAME}": writes the build number and the job name to the console. BUILD_NUMBER and JOB_NAME are environment variables that Jenkins defines for every build (below the Command field there is a link to the full list; you will study them in depth in Using Environment Variables).
  • git log -1 --oneline: shows the commit being built on a single line. It works because the workspace is a Git repository.
  • chmod +x mvnw: the permissions safeguard you already know.

Step 2 (Execute shell): the build.

./mvnw -B verify

To add the second step, click Add build step → Execute shell; you can reorder steps by dragging them by their handle. Save and start a build. In the console you will see both scripts, each with its own $ /bin/sh -xe /tmp/jenkins...sh line:

[orders-api-build] $ /bin/sh -xe /tmp/jenkins8812345678901234567.sh
+ echo Build 8 of job orders-api-build
Build 8 of job orders-api-build
+ git log -1 --oneline
4b1d2e7 Restore the order listing test
+ chmod +x mvnw
[orders-api-build] $ /bin/sh -xe /tmp/jenkins2234567890123456789.sh
+ ./mvnw -B verify
[INFO] Scanning for projects...

Notice that -x shows the command with the variables already substituted (Build 8 of…). Your build number will be different.

"Invoke Top-Level Maven Targets" vs. ./mvnw

In the Add build step drop-down you will also see Invoke top-level Maven targets, a Maven-specific step. Let's compare it with what we are doing:

Invoke top-level Maven targets Execute shell with ./mvnw
Maven version The installation configured in Manage Jenkins → Tools The one pinned in the repository itself (.mvn/wrapper/maven-wrapper.properties)
Prior setup Maven has to be registered in Tools None
Consistency with the developer's laptop May differ Identical
Portability to pipelines Freestyle-specific The same command will work in a pipeline sh step

That is why the course always uses the wrapper: the Maven version is decided by the project, not by the Jenkins configuration, and Diego builds on his machine exactly the way Jenkins builds on the server. Tool installations in Tools have their place, and you will see them in Integrating with Build Tools.

Post-build Actions: An Overview

Post-build actions run after the build steps, usually to publish results or send notifications. The main ones:

Action What it is for Where it is covered
Archive the artifacts Keep build files (the .jar) permanently 02-04
Record fingerprints of files to track usage Track a file across jobs 02-04
Publish JUnit test result report Publish test results (and get UNSTABLE) 06-03
E-mail Notification / Editable Email Notification Send email notifications 06-07
Delete workspace when build is done Delete the workspace when finished 02-04
Build other projects Trigger other jobs when finished Right now

Chaining Jobs: orders-api-smoke

Laura wants a smoke check to run after every successful build: a quick, shallow verification that the result is usable. For now it will be very simple: check that the .jar exists, that it is not empty and that it really is a JAR file.

Creating the Job

  1. New Item → name orders-api-smoke → Freestyle project → OK.
  2. Description: Smoke check of the orders-api jar. Triggered by orders-api-build.
  3. Source Code Management: leave it at None. This job does not need the source code.
  4. Build Steps → Execute shell:
JAR=/var/jenkins_home/workspace/orders-api-build/target/orders-api-1.0.0-SNAPSHOT.jar

echo "Smoke check of $JAR"

if [ ! -s "$JAR" ]; then
  echo "ERROR: the jar does not exist or is empty"
  exit 1
fi

ls -lh "$JAR"

if [ "$(head -c 2 "$JAR")" != "PK" ]; then
  echo "ERROR: the file is not in JAR/ZIP format"
  exit 1
fi

echo "Smoke OK: the jar exists and has a valid format"
  1. Save.

How the script works:

  • JAR=...: stores the path to the .jar in a variable so it does not have to be repeated. Notice that it points to another job's workspace: we will come back to this shortly.
  • [ ! -s "$JAR" ]: the -s test is true if the file exists and its size is greater than zero; ! negates it. If the jar is missing or empty, an error is written and exit 1 ends the script with a non-zero exit code, which makes the build fail.
  • ls -lh "$JAR": shows the file with its size in human-readable format (-h), useful as evidence in the console.
  • head -c 2 "$JAR": reads the first 2 bytes of the file. A JAR is a ZIP file, and every ZIP file starts with the letters PK (the initials of Phil Katz, who created the format). If it does not, the file is corrupt.
  • The quotes around "$JAR" are a good shell habit: they prevent problems if the path contains spaces.

Linking It from orders-api-build

  1. Open Configure in orders-api-build.
  2. Post-build Actions → Add post-build action → Build other projects.
  3. In Projects to build, type orders-api-smoke (Jenkins autocompletes the name).
  4. Keep Trigger only if build is stable selected.
  5. Save.

The three trigger options:

Option The next job is triggered if the build is…
Trigger only if build is stable SUCCESS
Trigger even if the build is unstable SUCCESS or UNSTABLE
Trigger even if the build fails SUCCESS, UNSTABLE or FAILURE

Click Build Now on orders-api-build. When it finishes, orders-api-smoke will start on its own. Its console will begin like this:

Started by upstream project "orders-api-build" build number 9
originally caused by:
 Started by user Laura Martin
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/orders-api-smoke
[orders-api-smoke] $ /bin/sh -xe /tmp/jenkins3345678901234567890.sh
+ JAR=/var/jenkins_home/workspace/orders-api-build/target/orders-api-1.0.0-SNAPSHOT.jar
+ echo Smoke check of /var/jenkins_home/workspace/orders-api-build/target/orders-api-1.0.0-SNAPSHOT.jar
...
-rw-r--r-- 1 jenkins jenkins 21M Nov 28 11:02 /var/jenkins_home/workspace/orders-api-build/target/orders-api-1.0.0-SNAPSHOT.jar
...
Smoke OK: the jar exists and has a valid format
Finished: SUCCESS

The cause is no longer a user but Started by upstream project, with the full chain of causes.

Upstream, Downstream and Their Limitations

In this relationship, orders-api-build is the upstream job and orders-api-smoke is the downstream job. If you open each job's page, you will see the Downstream Projects and Upstream Projects sections with a link to the other one.

flowchart LR
    U["orders-api-build<br/>(upstream)<br/>checkout + ./mvnw -B verify"] -->|"Build other projects<br/>if SUCCESS"| D["orders-api-smoke<br/>(downstream)<br/>checks the jar"]
    U -.->|"reads its workspace<br/>directly"| D

It works, but we have just built a fragile system. Look at its limitations:

  • Coupling to another job's workspace: orders-api-smoke reads an internal path belonging to another job. It only works because both run on the same node; with different agents, the file would not exist.
  • Race condition: if someone starts a new orders-api-build build while the check is running, Clean before checkout deletes target/ and the smoke check could fail, or check a jar from a different commit.
  • Hardcoded paths: if you rename orders-api-build, Jenkins updates the Build other projects reference, but not the path written inside the script.
  • Scattered flow: to understand the whole process you have to open two configurations; with five chained jobs, you lose the big picture.
  • No shared data: the downstream job receives no information from the upstream one (which commit, which build). Passing data to it would require additional plugins.

We will mitigate the first limitation in Workspaces, Artifacts and Build History by copying the archived artifact, and we will solve the underlying problem in Understanding Jenkins Pipelines.

The Lifecycle of a Job

Copying a Job (Copy From)

In New Item, type a new name and, instead of choosing a type, enter the name of an existing job in Copy from. Jenkins creates the new job with all the configuration of the original (but without its history). It is the quick way to create similar jobs.

Starting and Aborting

  • Build Now (job menu, context menu or the button in the list): puts a build in the queue.
  • To abort a running build, click the X next to its progress bar (on the job page, in Build Executor Status or in the console). The build ends in ABORTED and the console shows who stopped it (Aborted by ...).

Renaming

Job menu → Rename. The name, the URL and the workspace directory change for subsequent builds. Jenkins updates the references it knows about (such as Build other projects), but not paths written by hand in scripts or your browser bookmarks.

Disabling and Enabling

A disabled job keeps its configuration and history, but cannot be started: the Build Now button disappears, no trigger starts it and its icon turns gray. Useful for "parking" a job without losing it.

  • To disable it: in Configure, turn off the Enabled toggle at the top (in some versions, a Disable Project button on the job page).
  • To enable it: the job page shows the notice This project is currently disabled with an Enable button.

Deleting

Job menu → Delete Project, then confirm. The configuration and the entire history are deleted, including artifacts and consoles. There is no recycle bin: the only way back is a backup (you will see this in Backing Up and Restoring Jenkins). You can also delete a specific build with Delete build on its page.

Operation Keeps configuration? Keeps history? Reversible?
Disable Yes Yes Yes, with Enable
Rename Yes Yes Yes, by renaming again
Delete No No Only from a backup

Folders

A folder groups items under a common name. It provides:

  • A namespace: two folders can contain jobs with the same name.
  • Visual organization by team or product.
  • Per-folder permissions and credentials, which let you delegate management to each team (you will see this in Configuring Security).

A job inside a folder has a nested URL. For example, the example job inside the lab folder:

http://localhost:8080/job/lab/job/example/

And its workspace is created in /var/jenkins_home/workspace/lab/example. An existing job can be moved into a folder with the Move option in its menu.

Course decision: to keep the paths and URLs in the lessons simple and identical to yours, the TecnoShop jobs (orders-api-build, orders-api-smoke and those still to come) stay at the Jenkins root. In a real installation with several teams, organizing by folders is highly recommended. You will practice with them in exercise 2.

Common Mistakes and Tips

  • ERROR: the jar does not exist or is empty in orders-api-smoke: you started it by hand before orders-api-build generated the jar, or you mistyped the path. Run the upstream job first.
  • The downstream job does not start: check the condition. With Trigger only if build is stable, an upstream build in FAILURE does not trigger anything (which is what we want).
  • Mistyping the name in Projects to build: Jenkins shows a warning below the field if the job does not exist. Read it before saving.
  • Builds waiting indefinitely in the queue: it is almost always a Label Expression that no node satisfies. Hover over the queue item to see the reason.
  • Deleting a job to "start from scratch": you lose the history. If you only want to stop it, disable it.
  • Enabling Wipe out repository or Delete workspace when you do not need to: every build clones the entire repository. With large repositories, the cost is significant.
  • Tip: the Apply button saves without leaving the configuration page; use it when you are making several changes and want to check them as you go.

Exercises

Exercise 1. Create orders-api-build-copy as a copy of orders-api-build. Check that it has the same configuration but no builds. Disable it and try to start it. Then rename it to orders-api-build-temp and, finally, delete it. What happens to the TecnoShop view from the previous lesson at each step?

Exercise 2. Create a lab folder and, inside it, a Freestyle job called example whose only step is pwd followed by echo "Hello from a folder". Run it and note the path shown by pwd and the job's URL. When you are done, delete the entire folder.

Exercise 3. Break an orders-api test as you did in lesson 01-05, push it and start orders-api-build. Does orders-api-smoke start? What would change if you had chosen Trigger even if the build fails, and why would that make no sense here? Restore the test when you are done.

Solutions

Solution 1. In New Item, enter the name orders-api-build-copy and Copy from orders-api-build. The copy has both steps, the timeout and the Build other projects action, but its Build History is empty. When you disable it, Build Now disappears and the notice This project is currently disabled appears. In the TecnoShop view it shows up as soon as it is created (its name matches orders-.*), with a gray icon once it is disabled; it still appears after being renamed to orders-api-build-temp (which also matches) and disappears once it is deleted. One important detail: the copy also had Build other projects pointing to orders-api-smoke; if you had run it, it would have triggered the smoke check on the original job's jar, not on its own. This is yet another example of how fragile hardcoded paths are.

Solution 2. New Item → lab → Folder → OK → Save. Inside the folder, New Item → example → Freestyle project, with an Execute shell step:

pwd
echo "Hello from a folder"

The console will show /var/jenkins_home/workspace/lab/example and the job URL will be http://localhost:8080/job/lab/job/example/. To clean up, open the folder and use Delete Folder: the folder and all its contents are deleted.

Solution 3. orders-api-build ends in FAILURE and orders-api-smoke does not start, because the condition is Trigger only if build is stable. With Trigger even if the build fails, the smoke check would run anyway; since Maven never gets as far as packaging when the tests fail, and Clean before checkout has deleted target/, the check would fail with the jar does not exist or is empty, producing a second failure that adds no new information. Downstream checks only make sense on a successful build. Restore the test, push it and run the job again.

Conclusion

You now know the item types that New Item offers and when to use each one, and you have walked through the full configuration of a Freestyle project: the General options (concurrent builds, node restrictions), Git's additional behaviors such as Clean before checkout, Environment options such as the 15-minute timeout, multiple steps with the Maven Wrapper and an overview of Post-build Actions. You have chained orders-api-build to orders-api-smoke with Build other projects and seen the limitations of that approach, along with the lifecycle operations of a job and the role of folders. However, you are still starting every build by hand, and they always do exactly the same thing. In the next lesson, Parameters, Triggers and Build Scheduling, you will make orders-api-build accept parameters and run on its own, both on a schedule and when it detects changes in the repository.

© Copyright 2026. All rights reserved