Category: java
Introduction to Jenkins Pipeline
Published on 13 Aug 2026
Explanation
A Jenkins Pipeline defines the complete CI/CD workflow as code. Instead of configuring every step manually through the Jenkins UI, developers can define stages such as checkout, build, test, package, and deploy in a Jenkinsfile.
Code:
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'mvn clean package'
}
}
}
}
Explanation
A Jenkinsfile is a text file stored inside the source code repository. It defines the pipeline stages and commands Jenkins should execute, making the CI/CD process version-controlled and reproducible.
Code:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
}
}
Explanation
Jenkins Credentials securely store sensitive information such as Git passwords, SSH keys, Docker registry credentials, and cloud access keys. Credentials should never be hardcoded inside Jenkinsfiles.
Code:
withCredentials([
usernamePassword(
credentialsId: 'docker-creds',
usernameVariable: 'USER',
passwordVariable: 'PASS'
)
]) {
sh 'docker login -u $USER -p $PASS'
}
Explanation
Jenkins can automatically execute unit and integration tests after compiling the application. If tests fail, the pipeline can stop before deployment, preventing broken applications from reaching production.
Code:
stage('Test') {
steps {
sh 'mvn test'
}
}
Explanation
A typical Spring Boot CI pipeline checks out source code, builds the application, runs tests, packages the JAR, and publishes the build artifact. This provides immediate feedback whenever developers push code.
Code:
Checkout β Compile β Unit Test β Package β Artifact