The time has come for Jenkins to do its first real piece of work. You have the orders-api repository on GitHub and the jenkins-controller controller up and running; now you are going to connect them. In this lesson you will create, step by step, a Freestyle project called orders-api-build that fetches the code, builds it and runs its tests. You will learn how to start it, how to follow its progress and, above all, how to read the console output, the single most important skill for working with Jenkins day to day. Then you will deliberately break a test to see how Jenkins detects the failure and how to diagnose it.

What a Job Is and What a Freestyle Project Is

A job (also called an item or a project in the interface) is a task configured in Jenkins: it defines where the code comes from, what needs to run and what to do with the result. Every time a job runs, a build (a run) is created, numbered consecutively: #1, #2, #3...

Jenkins offers several types of jobs. The simplest is the Freestyle project: it is configured entirely through web interface forms. It is ideal for taking your first steps, although in the course we will move on to pipelines, which define the process as code (we will introduce them in Understanding Jenkins Pipelines).

Concept TecnoShop example
Job orders-api-build
Build Run #1 of orders-api-build
Build step Running ./mvnw -B verify
Result SUCCESS or FAILURE

Creating the orders-api-build Job

  1. Open http://localhost:8080 and sign in with your administrator user.
  2. On the main dashboard, click New Item in the left-hand side menu.
  3. Under Enter an item name, type orders-api-build.
  4. Select Freestyle project.
  5. Click OK.

Jenkins takes you to the job's configuration page, organized into sections (you will also see them in that page's side menu): General, Source Code Management, Triggers, Environment, Build Steps and Post-build Actions. In this lesson we will only use three of them; we will explore the rest in module 2.

About the name: the job name is part of its URL (http://localhost:8080/job/orders-api-build/) and of the name of its working directory. Use lowercase letters, numbers and hyphens; avoid spaces, accented letters and special characters.

General: The Description

In the Description field, write something useful for whoever comes after you, for example:

Builds and runs the tests for orders-api (main branch).
Freestyle learning job. Owner: platform team.

The description appears on the job's main page. It may seem like a minor detail, but once Jenkins has dozens of jobs you will be grateful to know what each one does without opening its configuration.

Configuring the Source Code: Git

In the Source Code Management section:

  1. Select Git. (This option comes from the Git plugin, which is included in the suggested plugins you installed in the wizard.)
  2. In Repository URL, paste your repository's HTTPS URL:
https://github.com/<your-username>/orders-api.git
  1. Leave Credentials set to - none -: the repository is public and Jenkins can clone it without authenticating.
  2. Under Branches to build → Branch Specifier, change the default value */master to:
*/main

What does */main mean? The asterisk stands for the name of the remote repository (usually origin). So */main tells Jenkins: "build the main branch from any configured remote". If you leave */master, the build will fail because your repository has no master branch.

When you leave the URL field, Jenkins tries to connect to the repository. If a red message like Failed to connect to repository appears, check that the URL is correct and that the repository is public.

Adding the Build Step

Scroll down to the Build Steps section:

  1. Click Add build step.
  2. Choose Execute shell (run a shell script).
  3. In the Command field, type:
chmod +x mvnw
./mvnw -B verify

What each line does:

  • chmod +x mvnw: ensures that the Maven Wrapper script has execute permission. If you recorded the permission with git update-index --chmod=+x mvnw in the previous lesson, this line is not strictly necessary; but if the repository was created or modified on Windows, Git may have stored the file without that permission, and the build would then fail with ./mvnw: Permission denied. This line is a harmless safeguard.
  • ./mvnw -B verify: runs Maven through the wrapper to compile, run the tests and package the .jar.
    • -B enables batch mode (non-interactive). On a server there is nobody to answer questions, and this mode also removes the download progress bars, which would flood the console output with thousands of useless lines.
    • verify runs all the Maven phases up to verification, including compile, test and package.

Jenkins runs this script with /bin/sh -xe:

  • -x makes each command appear in the console, prefixed with +, before it runs. That way you always know what is being executed.
  • -e stops the script as soon as a command exits with an error (an exit code other than 0). In that case, Jenkins marks the build as failed.

This is the fundamental rule: Jenkins decides whether a step succeeded or failed based on the command's exit code. Maven returns 0 if everything goes well and a different value if the compilation or any test fails.

Saving and Starting the First Build

  1. Click Save at the bottom of the page. You will land on the job's main page.
  2. In the side menu, click Build Now.

For a few moments, the build appears in the queue (as you saw in the architecture lesson) and then quickly starts running on the built-in node.

Expected warning: Manage Jenkins may display a warning saying that running builds on the built-in node is a security risk. That is correct: as you already know, it is a temporary simplification for the course that we will resolve in module 5.

Notice that we started the build manually. If you push to the repository now, Jenkins will not react on its own: you will configure automatic triggers in Parameters, Triggers and Build Scheduling.

Following the Build: Build History

On the job page you will see the Build History panel, with a #1 entry:

  • While it is running, it shows a progress bar or an animated icon.
  • When it finishes, it shows an icon with the result (green if it went well) and the date.

Click #1 to open the build page. There you will see its status, who started it, the Git revision used and, in the side menu, the Console Output option. Open it. If the build is still running, you will see the output grow in real time.

The first build will take a little longer than the following ones: ./mvnw has to download Maven and all of the project's dependencies. Those downloads are stored in /var/jenkins_home/.m2, inside the volume, so later builds will be faster.

Reading the Console Output Block by Block

The console output is the complete record of what happened in the build. Below is a condensed version (... marks omitted lines; commit identifiers and Maven plugin version numbers will differ in your case).

Block 1: Build Start

Started by user Laura Martin
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/orders-api-build
  • Started by user ...: who or what started the build. Here, a user clicking Build Now (your console will show the name of your own administrator user). Later you will see other causes, such as a change in Git or a time-based schedule.
  • Running as SYSTEM: the build runs under Jenkins' internal identity.
  • Building in workspace ...: the path of the workspace, the directory where the code will be fetched and the commands run.

Block 2: Fetching the Code (Checkout)

The recommended git tool is: NONE
No credentials specified
Cloning the remote Git repository
Cloning repository https://github.com/tecnoshop/orders-api.git
 > git init /var/jenkins_home/workspace/orders-api-build # timeout=10
Fetching upstream changes from https://github.com/tecnoshop/orders-api.git
 > git fetch --tags --force --progress -- https://github.com/tecnoshop/orders-api.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/main^{commit} # timeout=10
Checking out Revision 7c3e9a1f5b2d... (refs/remotes/origin/main)
 > git checkout -f 7c3e9a1f5b2d... # timeout=10
Commit message: "Initial version of orders-api"
First time build. Skipping changelog.
  • No credentials specified: no credentials are used, which is what you would expect for a public repository.
  • The lines starting with > are the Git commands Jenkins runs: it initializes the workspace as a repository (git init), fetches the branches (git fetch) and works out which commit main points to (git rev-parse).
  • Checking out Revision ...: the exact commit that is going to be built. This line is the key to traceability: you will always know which version of the code produced each build.
  • Commit message: the message of that commit.
  • First time build. Skipping changelog.: since this is the first build, there are no previous changes to compare against. From the second build onward, the build page will show the new commits under Changes.

Block 3: Running the Script

[orders-api-build] $ /bin/sh -xe /tmp/jenkins5023814462817319485.sh
+ chmod +x mvnw
+ ./mvnw -B verify
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.tecnoshop:orders-api >----------------------
[INFO] Building orders-api 1.0.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/...
...
  • $ /bin/sh -xe /tmp/jenkins...sh: Jenkins saves your command to a temporary script and runs it with -x and -e.
  • + chmod +x mvnw and + ./mvnw -B verify: thanks to -x, each command is displayed before it runs.
  • Building orders-api 1.0.0-SNAPSHOT: Maven has read the pom.xml and confirms the project and the version.
  • Downloading from central: dependencies being downloaded from Maven Central. In the first build you will see many lines like this; in subsequent ones, hardly any.

Block 4: Compilation and Tests

[INFO] --- compiler:3.x:compile (default-compile) @ orders-api ---
[INFO] Compiling 3 source files with javac [debug parameters release 21] to target/classes
...
[INFO] --- surefire:3.x:test (default-test) @ orders-api ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.tecnoshop.orders.OrderControllerTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.08 s -- in com.tecnoshop.orders.OrderControllerTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
  • compiler:...:compile: the Maven compiler plugin compiles the 3 classes of the main code (OrdersApiApplication, Order and OrderController) for Java 21.
  • surefire:...:test: Surefire is the Maven plugin that runs the tests. It automatically detects that we are using JUnit 5 (JUnit Platform).
  • Running com.tecnoshop.orders.OrderControllerTest: the test class being run.
  • Tests run: 3, Failures: 0, Errors: 0, Skipped: 0: the summary. 3 tests ran, none failed (Failures: an assertion did not hold), none hit an unexpected error (Errors: an unanticipated exception) and none were skipped (Skipped).

Block 5: Packaging and the Maven Result

[INFO] --- jar:3.x:jar (default-jar) @ orders-api ---
[INFO] Building jar: /var/jenkins_home/workspace/orders-api-build/target/orders-api-1.0.0-SNAPSHOT.jar
[INFO] --- spring-boot:3.x:repackage (repackage) @ orders-api ---
[INFO] Replacing main artifact ... with repackaged archive ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  25.412 s
[INFO] Finished at: 2026-11-28T10:15:42Z
[INFO] ------------------------------------------------------------------------
  • Building jar: .../target/orders-api-1.0.0-SNAPSHOT.jar: Maven generates the artifact inside the workspace.
  • spring-boot:...:repackage: the Spring Boot plugin turns that .jar into a self-contained executable.
  • BUILD SUCCESS: this is Maven's verdict. Maven will exit with code 0.

Block 6: The Jenkins Result

Finished: SUCCESS

This last line is Jenkins' verdict on the build as a whole. It is important to tell the two messages apart:

Message Who writes it What it means
BUILD SUCCESS / BUILD FAILURE Maven The result of the Maven run
Finished: SUCCESS / Finished: FAILURE Jenkins The final result of the build, taking all of its steps into account

In a job with several steps, Maven could finish successfully and the build could still fail because of a later step. The line that always has the final say is Finished:.

Deliberately Causing a Failure

A continuous integration system is only useful if it catches errors. Let's check that by deliberately breaking a test, as if Diego had pushed a faulty change.

In your local copy of orders-api, edit src/test/java/com/tecnoshop/orders/OrderControllerTest.java and change the expected value in the first test from 3 to 4:

    @Test
    void listReturnsThreeOrders() {
        assertEquals(4, controller.list().size());
    }

Now the test expects 4 orders, but the controller only has 3: the assertion will fail. Push the change:

git add src/test/java/com/tecnoshop/orders/OrderControllerTest.java
git commit -m "Deliberately broken test to see a failure in Jenkins"
git push

Notice that we are deliberately ignoring the advice to run ./mvnw -B verify locally before pushing. Do not do this in real life.

Go back to Jenkins and click Build Now on orders-api-build. Build #2 will appear and, when it finishes, it will be shown with a red icon.

Diagnosing and Fixing the Failure

Open the Console Output of build #2. The technique for reading a failed build is to start at the end and work your way up until you find the cause.

Step 1: The Final Result

Build step 'Execute shell' marked build as failure
Finished: FAILURE
  • Build step 'Execute shell' marked build as failure: the shell step exited with a non-zero exit code, so Jenkins marked it as failed.
  • Finished: FAILURE: the build has failed.

Step 2: The Maven Error

Moving up a little:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.x:test (default-test) on project orders-api: There are test failures.

Maven tells us which phase failed: the test goal of the Surefire plugin, because there are test failures. We now know it is not a compilation, network or Jenkins problem: it is a test.

Step 3: Which Test and Why

A bit further up is the Surefire summary:

[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.09 s <<< FAILURE! -- in com.tecnoshop.orders.OrderControllerTest
[ERROR] com.tecnoshop.orders.OrderControllerTest.listReturnsThreeOrders -- Time elapsed: 0.01 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <4> but was: <3>
	at com.tecnoshop.orders.OrderControllerTest.listReturnsThreeOrders(OrderControllerTest.java:15)
...
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   OrderControllerTest.listReturnsThreeOrders:15 expected: <4> but was: <3>
[INFO]
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0

All the information you need is here:

  • Which test failed: OrderControllerTest.listReturnsThreeOrders.
  • Where: line 15 of the OrderControllerTest.java file.
  • Why: expected: <4> but was: <3>; 4 elements were expected and there were 3.
  • Scope: out of 3 tests, 1 failed (Failures: 1).

In addition, on the page for build #2, the Changes section shows the commit "Deliberately broken test...", so you know exactly which change introduced the error. This is the big advantage over TecnoShop's manual process: the error is detected within minutes and points straight to its source.

Step 4: Fixing It

Undo the change in the test (set it back to 3), verify locally and push the fix:

./mvnw -B verify
git add src/test/java/com/tecnoshop/orders/OrderControllerTest.java
git commit -m "Restore the order listing test"
git push

Click Build Now again. Build #3 should end with Finished: SUCCESS. In Build History you will see the sequence #1 green, #2 red and #3 green: the history tells the story of the project.

Build Statuses

Status Usual icon Meaning Typical example
SUCCESS Green (check mark) All steps completed successfully Builds #1 and #3
FAILURE Red (cross) A step failed: a compilation error, a test failing under Maven, a command that does not exist... Build #2
UNSTABLE Yellow/orange (warning) The build completed, but the published reports indicate problems, usually failed tests Requires publishing test reports; you will see this in Integrating with Testing Tools
ABORTED Gray (crossed-out circle) The build was canceled manually or by a timeout Clicking the X on a running build
In progress Animated icon or progress bar The build is running While it runs

Why was build #2 a FAILURE and not UNSTABLE, if what failed was a test? Because our job only knows Maven's exit code, which was not 0. For Jenkins to distinguish "the code compiles but some tests fail" (UNSTABLE) from "something is broken" (FAILURE), you need to publish the test reports, which we will do later.

Where Did It All Run? The Workspace

All the work was done in the workspace shown on the first line of the console: /var/jenkins_home/workspace/orders-api-build, inside the jenkins-controller container. You can view its contents from the job page, with the Workspace option in the side menu, or from the terminal:

docker exec jenkins-controller ls /var/jenkins_home/workspace/orders-api-build/target

That is where orders-api-1.0.0-SNAPSHOT.jar lives. But remember: the workspace is a working directory, not permanent storage, and the next build will overwrite it. You will learn how to keep artifacts and manage build history in Workspaces, Artifacts and Build History.

Common Mistakes and Tips

  • Couldn't find any revision to build: the Branch Specifier does not match any branch. It is almost always */master when the branch is main.
  • Failed to connect to repository / Authentication failed: a mistyped URL or a private repository. Check the URL by copying it from GitHub's Code button, and make sure the repository is public.
  • ./mvnw: Permission denied: the execute permission is missing. The chmod +x mvnw line fixes it; the permanent fix is git update-index --chmod=+x mvnw in the repository.
  • ./mvnw: not found: you did not push the wrapper to GitHub. Check that mvnw and .mvn/ are in the repository.
  • /bin/sh: 1: ./mvnw: not found even though the file is there: this can be caused by Windows line endings (CRLF) in mvnw. Configure Git to use LF line endings for that file (for example, with a .gitattributes file containing mvnw text eol=lf) and push it again.
  • Expecting the build to start on its own when you push: we have not configured triggers yet; for now, use Build Now.
  • Reading the console from the top: with thousands of lines, start at the end (Finished:), move up to BUILD FAILURE or the first relevant [ERROR], and pin down the cause.
  • Tip: when you share a problem with your team, link to the build URL (for example, http://localhost:8080/job/orders-api-build/2/console) instead of pasting loose fragments.

Exercises

Exercise 1. Run two builds of orders-api-build back to back without changing anything. Compare the Total time line and the number of Downloading from lines in the console of each. What difference do you notice, and why does it happen? Does anything appear under Changes for the second build?

Exercise 2. This time, cause a compilation error: in OrderController.java, delete the semicolon at the end of the return ORDERS; line, commit, push and start a build. Find in the console which plugin and phase Maven fails in, and compare it with the test failure from this lesson. Then fix it.

Exercise 3. Temporarily modify the job's Execute shell step to add sleep 60 before ./mvnw -B verify. Start a build and cancel it while it is waiting. What status does it get? What does the last line of the console show? When you are done, remove the sleep 60.

Solutions

Solution 1. The second build takes considerably less time and shows almost no Downloading from lines, because Maven and the dependencies are already in the /var/jenkins_home/.m2 cache, which is kept in the volume. In addition, the workspace already contains the cloned repository, so Git only fetches what is new. Nothing appears under Changes for the second build (No changes), because there are no new commits since the previous build: the same revision was built.

Solution 2. The console will show something similar to:

[ERROR] COMPILATION ERROR :
[ERROR] /var/jenkins_home/workspace/orders-api-build/src/main/java/com/tecnoshop/orders/OrderController.java:[23,22] ';' expected
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.x:compile (default-compile) on project orders-api: Compilation failure
...
Finished: FAILURE

The key difference is where it fails: this time it is the maven-compiler-plugin in the compile phase, before reaching the tests (no T E S T S block appears); in the failure from the lesson it was the maven-surefire-plugin in the test phase. The message gives the file, line and column ([23,22]; the numbers may vary slightly depending on your file). Both cases end in FAILURE. To fix it, put the semicolon back, verify locally and push.

Solution 3. The build gets the ABORTED status (gray icon) and the console ends with:

+ sleep 60
Aborted by Laura Martin
Finished: ABORTED

The name shown will be your own user's. The ABORTED status indicates that the build did not fail by itself; someone (or a time limit) stopped it. Remember to remove the sleep 60 and save the configuration.

Conclusion

You have created your first Jenkins job, the orders-api-build Freestyle project, which fetches the main branch of your repository with Git and runs ./mvnw -B verify on the built-in node. You know how to start it with Build Now, follow it in Build History and, most importantly, read the Console Output block by block: the start, the checkout with its exact revision, the script run, compilation and tests, Maven's BUILD SUCCESS and Jenkins' Finished:. By deliberately breaking a test you have seen how Jenkins catches the error within minutes and how to diagnose it by reading the console from the bottom up, and you know the SUCCESS, FAILURE, UNSTABLE and ABORTED statuses. This wraps up the introductory module: you now have Jenkins up and running and verifying your code. In the next module you will dig into working with Jenkins day to day, starting with the Jenkins Dashboard Overview, where you will learn to find your way around its entire interface.

© Copyright 2026. All rights reserved