Master Jenkins From Beginner to Enterprise

Clear, interactive, and structured Jenkins lessons designed to take you from beginner to enterprise level.

Build Steps

Learn the concepts, syntax types, script execution hooks, and workflow blocks required to compile, test, and package applications inside Jenkins pipelines.

What are Build Steps?

Build Steps represent the core functional actions executed within a pipeline stage. After code has been retrieved from source control, build steps instruct the agent node exactly how to interact with compilers, run testing frameworks, or package deployable binaries.

Simple Definition: Build Steps are individual, sequential commands or plugin actions executed within a pipeline stage to carry out physical tasks like compiling source files, running unit tests, or executing shell scripts.

Common Build Step Families

Jenkins categorizes execution steps based on the target runtime environment and configuration type:

  • Shell Executions (`sh`): Native terminal command lines executed inside POSIX-compliant environments such as Linux or macOS agent nodes.
  • Windows Batch Commands (`bat`): Command-line execution loops run specifically on Windows-based worker nodes using traditional command prompt syntax.
  • Managed Tool Wrappers: Native steps backed by installed plugins that abstract command-line paths for engines like Maven (`mvn`), Gradle, or npm.

Key Concepts

Sequential Execution & Failures

Understanding that step steps execute top-to-bottom. If any individual shell command returns a non-zero exit code, Jenkins marks that step as failed and halts the pipeline immediately.

Workspace Environment Isolation

Recognizing that all script steps run relative to the current build's isolated workspace directory, giving commands native access to cloned files and dependencies.

Practical Jenkins Example

The following multi-stage declarative pipeline demonstrates how to implement specialized compilation, test, and packaging steps sequentially:

pipeline {
    agent any
    stages {
        stage('Compile Application') {
            steps {
                echo 'Starting application compilation stage...'
                // Simulating a project dependency setup and compilation
                sh 'mkdir -p build/'
                sh 'echo "Compiling source files..."'
            }
        }
        stage('Run Code Verification') {
            steps {
                echo 'Initiating automated code quality and linting validation...'
                sh 'echo "Executing unit tests... Success!"'
            }
        }
        stage('Package Artifacts') {
            steps {
                echo 'Bundling successfully verified source files into distribution format...'
                sh 'tar -czf build/application-package.tar.gz build/'
                echo 'Application distribution ready for deployment storage.'
            }
        }
    }
}

Practice Exercise: Build and Package a Mock Application

Step-by-Step Task Sequence:
  1. Open an existing test pipeline configuration script or create a new Pipeline item from your dashboard.
  2. Replace your pipeline script block text with the complete practical code layout provided in the example above.
  3. Click the green Save button to commit the code configurations to the controller storage layer.
  4. Trigger a manual run iteration path by clicking the Build Now menu link on the left side menu sidebar.
  5. Click the current build iteration counter box, navigate to Console Output, and trace how each individual `sh` step prints its output back to the log history screen.

Summary

You have completed the Build Steps lesson. Continue through the syllabus to learn how to automatically execute these compilation steps using dynamic automated build triggers.