So far, orders-api-build has two obvious shortcomings: it always does exactly the same thing, and it only runs when someone clicks Build Now. On a real team, that is not enough. Diego sometimes wants to run a quick build without tests just to check that the code compiles; Laura wants a full build every night, even if nobody asks for one; and the whole team wants Jenkins to react on its own whenever someone pushes changes to main. In this lesson you will learn the two tools that make this possible: parameters, which let the same job behave differently on each run, and triggers, which decide when a build starts without human intervention, including time-based scheduling with Jenkins' cron syntax.

Parameterized Builds: What They Are and What They Are For

A parameter is a value that is requested (or received) when a build starts and that the job can use while it runs. With parameters, a single job can cover variants that would otherwise force you to duplicate it:

  • Running the tests or not.
  • Building one branch or another.
  • Specifying the target environment for a deployment.
  • Passing in a version number or a note.

Jenkins exposes each parameter to the build as an environment variable with the same name. That is why parameter names follow the environment variable convention: uppercase letters, numbers and underscores, with no spaces or accented characters (RUN_TESTS, not run tests).

Parameter Types

When you check This project is parameterized in the General section and click Add Parameter, these types appear:

Type What it asks for Value the build receives Example use
String Parameter A single line of text The text as is A branch, a version, a note
Choice Parameter A value from a fixed list The chosen value Target environment
Boolean Parameter A checkbox true or false (as text) Turning a phase on or off
Multi-line String Parameter Multi-line text The text with line breaks Release notes
Password Parameter Text hidden with asterisks The text in plain form See the warning below
Credentials Parameter A credential from the Jenkins store The credential's ID Covered in Credentials and Secrets Management
File Parameter A file uploaded from the browser The file, copied into the workspace A test data file

Each parameter has a Name, a Description and, depending on the type, a default value (for a Choice Parameter, the default is the first option in the list).

Two important warnings:

  • Password Parameter is not a secure way to handle secrets. The interface hides the value as you type it, but the build receives it in plain text: if it appears in a command, /bin/sh -x will print it in the console, where anyone with access to the job can read it. For passwords and tokens, use Jenkins credentials, which mask values in the console.
  • File Parameter works in Freestyle jobs but causes problems in pipelines, where a dedicated plugin is used instead. In practice, it is rarely used.

Parameterizing orders-api-build: RUN_TESTS and ENVIRONMENT

Open Configure in orders-api-build, check This project is parameterized and add two parameters.

Parameter 1: Add Parameter → Boolean Parameter

Field Value
Name RUN_TESTS
Default Value / Set by Default Checked
Description Uncheck only to quickly verify that the code compiles. Never for a build that is going to be deployed.

Parameter 2: Add Parameter → Choice Parameter

Field Value
Name ENVIRONMENT
Choices One option per line (see below)
Description Target environment. Informational only for now: deployment arrives in module 7.

In Choices, enter one per line:

dev
staging
production

Since dev comes first, it will be the default value. This is a deliberate decision: the default value should always be the least dangerous one, because it is the value used when the build is started by an automatic trigger or by someone who is not reading carefully.

Using Parameters in the Shell

Now modify the steps you configured in Creating and Running Jobs.

Step 1 (Execute shell): add a line at the end.

echo "Build ${BUILD_NUMBER} of job ${JOB_NAME}"
git log -1 --oneline
chmod +x mvnw
echo "Target environment: ${ENVIRONMENT} (informational only for now)"

Step 2 (Execute shell): replace its contents with:

if [ "$RUN_TESTS" = "true" ]; then
  ./mvnw -B verify
else
  echo "WARNING: skipping tests (RUN_TESTS=false)"
  ./mvnw -B -DskipTests verify
fi

Let's take this bash if apart piece by piece, because it is a pattern you will use constantly:

  • if [ ... ]; then: [ is actually a command (equivalent to test) that evaluates a condition and returns exit code 0 (true) or 1 (false). The spaces around [ and ] are mandatory: ["$RUN_TESTS" = "true"] causes an error.
  • "$RUN_TESTS" = "true": compares two strings. Remember that a Boolean Parameter arrives as the text true or false, not as a boolean. The quotes around the variable prevent errors if it is empty.
  • The then branch: a full build with ./mvnw -B verify, as before.
  • The else branch: prints a warning to the console and runs ./mvnw -B -DskipTests verify. The -DskipTests property makes Maven compile the tests but not run them; the .jar is still generated.
  • fi: closes the if (it is if spelled backwards).

So why not simply write ./mvnw -B $OPTIONS verify? You could, but the if leaves an explicit warning in the console when the tests are skipped. A green build without tests should be easy to spot.

Save the configuration.

Build with Parameters and Parameters on the Build Page

Once the job is parameterized, the Build Now link becomes Build with Parameters. When you click it, Jenkins shows a form with both parameters, their default values and their descriptions. Start a build with RUN_TESTS unchecked and staging selected:

Started by user Laura Martin
...
+ echo Target environment: staging (informational only for now)
Target environment: staging (informational only for now)
[orders-api-build] $ /bin/sh -xe /tmp/jenkins4456789012345678901.sh
+ [ false = true ]
+ echo WARNING: skipping tests (RUN_TESTS=false)
WARNING: skipping tests (RUN_TESTS=false)
+ ./mvnw -B -DskipTests verify
...
[INFO] Tests are skipped.
...
[INFO] BUILD SUCCESS
...
Finished: SUCCESS

Notice the line + [ false = true ]: thanks to -x you see the condition with the parameter's actual value already substituted. It is the best way to debug an if that does not behave as you expect. And in the test phase, Maven reports Tests are skipped..

The page for that build now shows a Parameters link in the side menu, with the values that were used:

Parameter Value
RUN_TESTS false (checkbox unchecked)
ENVIRONMENT staging

This matters for traceability: months later you will still be able to tell which values each build ran with. In addition, a build's context menu shows a Rebuild option only if you have the corresponding plugin installed; without it, just use Build with Parameters again.

Keep in mind that orders-api-smoke will still be triggered after this build, because the result is SUCCESS. The downstream job does not receive the upstream job's parameters; this is another of the chaining limitations you saw in the previous lesson.

Triggers: An Overview

A trigger is any mechanism that puts a build in the queue without anyone clicking a button. In a Freestyle project they are configured in the Triggers section (Build Triggers in earlier versions):

Trigger Starts when… Recommended use
Build periodically A scheduled time arrives Nightly builds, maintenance tasks
Poll SCM Jenkins checks the repository and detects new commits A temporary solution when webhooks are not available
Build after other projects are built Another job finishes Simple chaining
Trigger builds remotely An HTTP request with a token arrives Integration with scripts or external systems
GitHub hook trigger for GITScm polling GitHub reports a push through a webhook The recommended way to react to changes

Every build records its cause on the first line of the console (Started by...), so you will always know what triggered it.

Build Periodically and Jenkins' Cron Syntax

Build periodically starts the build according to a schedule written in a syntax derived from cron, the classic Unix task scheduler.

The Five Fields

Each line has five fields separated by spaces or tabs:

MINUTE  HOUR  DAY_OF_MONTH  MONTH  DAY_OF_WEEK
 0-59   0-23      1-31      1-12      0-7

For the day of the week, both 0 and 7 mean Sunday; 1 is Monday. In each field you can use:

Symbol Meaning Example Reading
* Any value * in HOUR Every hour
N A specific value 30 in MINUTE At minute 30
A-B A range 1-5 in DAY_OF_WEEK Monday through Friday
A,B,C A list 8,14,20 in HOUR At 8:00, 14:00 and 20:00
*/N Every N */15 in MINUTE Minutes 0, 15, 30 and 45
H A value calculated from the job name H in MINUTE A fixed minute, different for each job

The H Symbol and Why It Exists

Imagine that TecnoShop has 50 jobs, all scheduled with 0 2 * * * (at 2:00). At exactly 2:00, 50 builds would enter the queue at once, saturating the executors, the network and the repository, while Jenkins would sit idle for the rest of the night.

The H symbol (for hash) solves this problem: Jenkins calculates a value from the job name. This means that:

  • Each job gets a different value, so the load is spread out.
  • For a given job, the value is always the same: H 2 * * * in orders-api-build will run, for example, every day at 2:37, not at a random time each day.

H supports ranges and intervals: H(0-29) picks a value between 0 and 29, and H/15 means "every 15 minutes, starting at a calculated minute" (for example, 7, 22, 37 and 52). Use H whenever you do not need an exact time; the Jenkins interface itself will suggest it with a warning if you type */15 or a fixed 0.

Aliases

Alias Equivalent to Meaning
@hourly H * * * * Once an hour
@daily H H * * * Once a day, at any time
@midnight H H(0-2) * * * Once a day, between 00:00 and 02:59
@weekly H H * * H Once a week
@monthly H H H * * Once a month

Be careful with @daily: because it also uses H for the hour, the build may run at 15:00, in the middle of the working day. If you want it to run at night, use @midnight or write the time yourself.

Examples

Expression Runs…
H/15 * * * * Every 15 minutes, with a job-specific offset
H 2 * * 1-5 Once between 2:00 and 2:59, Monday through Friday
H H(0-5) * * * Once a day between 0:00 and 5:59
H 9-18/3 * * 1-5 At 9:00, 12:00, 15:00 and 18:00 (at a fixed minute), Monday through Friday
30 7 * * 1 Mondays at exactly 7:30
H H 1 * * On the 1st of every month, at a calculated time

You can write several lines in the field, one schedule per line, as well as comments starting with #.

Time Zone

By default, times are interpreted in the controller's time zone. In a Docker container this is usually UTC, which means H 2 * * * would run at 3:00 or 4:00 in Spain, depending on the time of year. To avoid surprises, specify the time zone on the first line:

TZ=Europe/Madrid
H 2 * * 1-5
  • TZ=Europe/Madrid: interprets the following lines in mainland Spain time, including daylight saving time changes.

Below the field, Jenkins instantly shows when the job would last have run and when it will run next, something like Would last have run at ... ; would next run at .... Always check it before saving: it is the most reliable way to spot a mistake in the expression.

Poll SCM: Checking the Repository Periodically

Poll SCM uses the same cron syntax, but instead of starting a build every time, Jenkins asks the repository whether there are new commits on the configured branch. Only if there are does it start a build.

sequenceDiagram
    participant J as Jenkins
    participant G as GitHub
    loop Every 15 minutes (H/15)
        J->>G: git ls-remote: which commit does main point to?
        G-->>J: commit 4b1d2e7
        alt The commit is the one from the last build
            J->>J: No changes (does nothing)
        else There is a new commit
            J->>J: Queues a build (Started by an SCM change)
        end
    end

Every check is logged on the job page, under the Git Polling Log link:

Started on Nov 28, 2026, 11:22:00 AM
Using strategy: Default
[poll] Last Built Revision: Revision 4b1d2e7... (refs/remotes/origin/main)
 > git ls-remote -h -- https://github.com/tecnoshop/orders-api.git # timeout=10
Found 1 remote heads on https://github.com/tecnoshop/orders-api.git
[poll] Latest remote head revision on refs/heads/main is: 4b1d2e7...
Done. Took 0.48 sec
No changes

When there are changes, the resulting build starts with Started by an SCM change.

The Cost of Polling

Polling works, but it has drawbacks:

  • Delay: with H/15, a commit may wait up to 15 minutes before it is built.
  • Pointless checks: the vast majority of checks come back with No changes. With 100 jobs polling every 5 minutes, that is 28,800 requests a day to the Git server.
  • Provider limits: services such as GitHub rate-limit requests; aggressive polling can lead to temporary blocks.

The right alternative is webhooks: the Git server notifies Jenkins at the exact moment of the push. No delay and no pointless checks. You will configure them in Integrating with Version Control Systems. In our lab environment, Jenkins runs on localhost and GitHub cannot reach it, which is why polling is a reasonable temporary solution.

Build After Other Projects Are Built

This trigger is the flip side of the Build other projects action you used in Creating and Running Jobs. Both create the same upstream/downstream relationship, but they are declared in different places:

Mechanism Configured in… Reads as…
Build other projects (Post-build Action) The upstream job (orders-api-build) "When I finish, start orders-api-smoke"
Build after other projects are built (Trigger) The downstream job (orders-api-smoke) "Start me when orders-api-build finishes"

In Projects to watch you list the jobs to watch and choose the condition: only if stable, even if unstable, even if it fails, or always (even if aborted).

Which one should you use? The result is the same; choose based on who "owns" the relationship. If the QA team maintains the downstream job and does not want to touch the upstream configuration, the trigger is more convenient. What matters is declaring the relationship on one side only: doing it on both is redundant and confuses whoever maintains the jobs. At TecnoShop we will keep the Build other projects action you already have.

Trigger Builds Remotely

This option lets you start a build with an HTTP request, for example from a script or from another tool. When you check it, Jenkins asks for an Authentication Token: a string that must accompany the request.

Suppose you configure the token tecnoshop-fake-token. Since orders-api-build has parameters, the URL is buildWithParameters (for a job without parameters it would be build):

curl -X POST \
  -u "laura:11aa22bb33cc44dd55ee66ff77fake00" \
  "http://localhost:8080/job/orders-api-build/buildWithParameters?token=tecnoshop-fake-token&ENVIRONMENT=staging&RUN_TESTS=false&cause=Triggered+from+script"
  • -X POST: requests that change anything in Jenkins must be POST requests.
  • -u "laura:...": with security enabled, Jenkins also requires you to authenticate with a user and their API token (the value in the example is fake). API tokens and the REST API are covered in Automating Jenkins with the REST API and CLI.
  • token=...: the token configured in the job.
  • ENVIRONMENT=staging&RUN_TESTS=false: the parameter values; any you leave out take their default value.
  • cause=...: an optional note that will appear in the build cause.

The build will start with a line like Started by remote host 172.18.0.1 with note: Triggered from script.

Security: anyone who knows the URL with the token and has access to Jenkins can start the build. Treat the token as a secret, do not publish it in repositories and do not enable it if you do not need it. At TecnoShop we will not leave it enabled.

GitHub Hook Trigger

The GitHub hook trigger for GITScm polling option is provided by the GitHub plugin. With it, when GitHub reports a push through a webhook, Jenkins checks which jobs use that repository and builds them if there are changes. This is the piece that will replace polling, and it is configured, along with the webhook on GitHub, in Integrating with Version Control Systems.

Quiet Period

The quiet period is the number of seconds a build waits in the queue before starting. In the meantime, the queue item shows In the quiet period. Expires in 4.6 sec.

Why wait? To group triggers together. If Diego pushes three times in 30 seconds, without a wait several almost identical builds would start; with a quiet period of, say, 60 seconds, identical requests that arrive during the wait are merged into a single build that includes all three commits.

  • The global default is 5 seconds and is set in Manage Jenkins → System.
  • Each job can override it in General → Advanced → Quiet period.
  • Even when you click Build Now you will sometimes see those few seconds of waiting in the queue: that is the quiet period at work.

A long quiet period delays every build of the job, so use it sparingly: between 30 and 120 seconds is reasonable for jobs that receive many changes in quick succession.

The TecnoShop Case: Nightly Build and Temporary Polling

Laura settles on the following strategy for orders-api-build:

  • A full nightly build Monday through Friday, to catch problems that do not depend on a commit (for example, an external dependency that is no longer available).
  • Polling every 15 minutes as a temporary way to react to changes, until webhooks are in place in module 6.

In Configure → Triggers for orders-api-build:

  1. Check Build periodically and enter:
TZ=Europe/Madrid
# Full nightly build, Monday through Friday
H 2 * * 1-5
  1. Check Poll SCM and, in Schedule, enter:
TZ=Europe/Madrid
# Temporary until webhooks are configured (module 6)
H/15 * * * *
  1. Save.

Which parameters do builds started by these triggers use? The default values: RUN_TESTS checked and ENVIRONMENT=dev. That is precisely why we chose those defaults: an automatic build should always be complete and safe.

From now on, Build History will contain builds with different causes:

Cause in the console Origin
Started by user Laura Martin Manual Build with Parameters
Started by timer Build periodically (nightly build)
Started by an SCM change Poll SCM detecting a new commit

Check it: make a small change in orders-api (in a comment, for example), push it with git push and wait. Within 15 minutes a build with the cause Started by an SCM change will appear, followed by the orders-api-smoke build.

Common Mistakes and Tips

  • [: missing ] or [false: not found: the spaces around [ and ] in the if are missing. The correct syntax is [ "$VAR" = "true" ].
  • Comparing a Boolean as a number or without quotes: the value is the text true or false. Compare with = "true".
  • A parameter name with different capitalization: $run_tests is not $RUN_TESTS. Environment variables are case-sensitive.
  • A dangerous default value: a Choice Parameter with production in first position will make every automatic build target production. The first value in the list should be the most harmless.
  • Cron without a time zone: the "2:00" build runs at 3:00 or 4:00. Add TZ=Europe/Madrid and check the would next run at text.
  • Using */5 or * * * * * in Poll SCM: constant requests to the Git server, possible blocks and a busy controller. Use H/15 or longer and plan the move to webhooks.
  • Expecting Poll SCM to start a build without changes: if there are no new commits, polling does nothing, even when its time comes around. That is what Build periodically is for.
  • Password Parameter for real secrets: it shows up in the console. Use credentials.
  • Tip: always write a Description for each parameter. It is what the person starting the build will see in the form.

Exercises

Exercise 1. Write the cron expression (using H where appropriate) for each case: (a) every 30 minutes; (b) once a day between 22:00 and 23:59, Madrid time; (c) on Saturdays at any time in the morning (from 6:00 to 11:59); (d) on the first day of every month at exactly 8:00.

Exercise 2. Add a String Parameter called NOTE (empty by default) to orders-api-build and make step 1 print Build note: <value> only if something was entered. Start one build with a note and another without one, and check the console and the Parameters page of both.

Exercise 3. Diego configures Poll SCM with * * * * * "so that builds come out sooner". Explain what problems this can cause, what temporary alternative you would propose and what the definitive solution is.

Solutions

Solution 1.

# (a) Every 30 minutes
H/30 * * * *

# (b) Once a day between 22:00 and 23:59, Madrid time
TZ=Europe/Madrid
H H(22-23) * * *

# (c) Saturdays, once between 6:00 and 11:59
H H(6-11) * * 6

# (d) The 1st of every month at exactly 8:00
0 8 1 * *

In (b), TZ applies to the lines that follow it, so if you write it on the first line of the field it applies to all of them. In (d) we use a fixed 0 because the exercise asks for an exact time; Jenkins will show a warning suggesting H, but it is a deliberate choice.

Solution 2. Add a String Parameter with the Name NOTE and an empty default value. At the end of step 1:

if [ -n "$NOTE" ]; then
  echo "Build note: $NOTE"
fi

-n is true if the text is not empty. In the build with a note you will see Build note: ...; in the other one, the console will show + [ -n ] and print nothing else. In both cases, Parameters shows the value (empty in the second). If you do not want to keep this parameter, remove it when you are done: we will not use it in the rest of the course.

Solution 3. * * * * * checks GitHub every minute: 1,440 requests a day per job, nearly all of them returning No changes, which load the controller and may cause GitHub to rate-limit the requests. What is more, the benefit is small: at most you save a few minutes compared with H/15. As a temporary alternative, use H/15 * * * * (or H/5 if the delay really is a problem). The definitive solution is GitHub webhooks with the GitHub hook trigger for GITScm polling trigger, which build instantly and without pointless checks (06-01).

Conclusion

orders-api-build is no longer a rigid, manual job. With the RUN_TESTS and ENVIRONMENT parameters, a single job covers several variants, which are used in the shell as environment variables and are recorded on each build's Parameters page. With triggers, the job runs on its own: a nightly build with TZ=Europe/Madrid and H 2 * * 1-5, and H/15 * * * * polling as a temporary solution until webhooks are in place. You know Jenkins' cron syntax and the reason behind the H symbol, remote triggers, the relationship between Build after other projects are built and Build other projects, and what the quiet period is for. Now that builds are multiplying, new questions arise: where their files pile up, how to keep the .jar from each build and how to stop the history from filling up the disk. You will answer them in Workspaces, Artifacts and Build History.

© Copyright 2026. All rights reserved