Search⌘ K
AI Features

Jenkins Kata 2: Build Steps

Explore how to configure Jenkins build steps by adding and customizing shell scripts to automate tasks. Understand the role of exit codes in signaling job success or failure, enabling efficient continuous integration feedback and error handling in your workflows.

Jenkins jobs execute build steps. Build steps can be general-purpose scripts or custom steps designed for a specific purpose. This kata will show us how to configure the basic steps in a job.

Step 1: Add a build step

To execute a build step that writes the build number to a file.

  • Click “Configure.”
  • Click the “Build Steps” tab.
  • Click “Add build step.”
  • Click “Execute shell.”
  • Enter the following code into the “Command” field:
Shell
echo Build ${BUILD_NUMBER} at $(date) > buildlog.txt
  • Click “Save.”
Click the "Configure" tab
Click the "Configure" tab
Click "Execute shell"
Click "Execute shell"
The "Execute shell" command field
The "Execute shell" command field

Commands

Command / Parameter

Description

echo

This writes text to standard output.

Build ${BUILD_NUMBER} at $(date)

This is the text to write out.

  • `Build` and `at` are text.
  • ${BUILD_NUMBER}: This is a Jenkins environment variable that's set to the ID of the running build.
  • $(date): This is an environment variable that returns the current date.

This script simply appends a new line, including the build number and the ...