Build Steps
Build steps are the individual commands a job runs, such as executing a shell script or invoking a build tool.
Syntax
# Execute shell step
npm install
npm run buildA build step is a single action Jenkins performs during a build. A job runs its steps in order, top to bottom. If any step fails, the build stops and is marked as failed.
Common build steps
- Execute shell (Linux/macOS) — run a shell script.
- Execute Windows batch command — run a
.batscript. - Invoke Gradle / Maven — run a Java build tool with plugin support.
- Invoke top-level Maven targets — run specific Maven goals.
Exit codes matter
Jenkins decides success or failure from the step's exit code. An exit code of 0 means success; anything else fails the build. This is why set -e is common in shell steps — it stops on the first error.
Example
#!/bin/bash
set -e # stop on first error
echo "Installing dependencies"
npm ci
echo "Running the build"
npm run build
echo "Running tests"
npm testWhen to use it
- A pipeline first runs unit tests in one step, then integration tests in a second step so failures are isolated.
- A build step invokes a custom Python script that generates a version file before the Docker image is built.
- A Windows build step calls a batch file to compile a .NET solution while a subsequent step runs MSTest.
More examples
Multiple shell build steps
Shows three ordered shell build steps that compile, test, and package a Node.js application.
# Step 1 – compile
npm install && npm run build
# Step 2 – test (separate build step in the UI)
npm test -- --coverage
# Step 3 – package
tar czf dist.tar.gz dist/Windows batch build step
Demonstrates a Windows batch build step that calls MSBuild to compile a .NET solution.
:: Execute Windows Batch Command build step
CALL build.bat
MSBuild MyApp.sln /t:Build /p:Configuration=Release
echo Build completed with exit code %ERRORLEVEL%Build step calling a Python script
Runs a Python version-generator script and passes its output as a Docker build argument.
#!/bin/bash
# Build step: Execute shell
python3 scripts/gen_version.py > version.txt
cat version.txt
docker build \
--build-arg VERSION=$(cat version.txt) \
-t myapp:$(cat version.txt) .
Discussion