Overview
This document provides a complete reference for the Jenkinsfile used in the CI/CD pipeline. The pipeline is written using Jenkins Declarative Pipeline syntax and includes four stages: Clone, Build, Test, and Deploy.Complete Jenkinsfile
Pipeline Configuration
Specifies where the pipeline will execute.
any means the pipeline can run on any available agent.Environment Variables
Environment variables are defined at the pipeline level and are accessible across all stages.The name of the Docker image to be built and deployed.
Stages
Clone Stage
Clones the source code repository from GitHub.The Git branch to clone from the repository.
The GitHub repository URL to clone from.
Build Stage
Builds the Docker image using the Dockerfile in the repository.IMAGE_NAME environment variable and tags the image as latest.
Test Stage
Installs dependencies and runs the test suite.|| operator for fallback.
Deploy Stage
Deploys the Docker container and exposes it on port 80.The name assigned to the Docker container.
Runs the container in detached mode (background).
Port mapping from host port 80 to container port 3000.
Post-Build Actions
Post-build actions execute after all stages complete, regardless of success or failure.Always Block
Executes regardless of pipeline result.Success Block
Executes only when the pipeline completes successfully.Failure Block
Executes only when the pipeline fails.Execution Flow
- Clone: Repository is cloned from GitHub
- Build: Docker image is built with tag
nodejs-demo-app:latest - Test: NPM dependencies are installed and tests are executed
- Deploy: Docker container is started on port 80
- Post: Appropriate post-build action executes based on pipeline result