Answer
Freestyle vs Pipeline Jobs in Jenkins
Freestyle Job
- ✓Configured entirely through the Jenkins web UI
- ✓No code required — click and configure
- ✓Good for simple tasks: run a shell script, trigger Maven, send email
- ✓Not version-controlled — config lives in Jenkins, not Git
- ✓Limited to single sequence of steps
CODE
Jenkins UI → Source Code Mgmt → Build Steps → Post-build Actions
When to use Freestyle:
- ✓Quick one-off jobs
- ✓Simple build/test without complex logic
- ✓Teams new to Jenkins
Pipeline Job
- ✓Written as a Jenkinsfile (Groovy DSL) stored in the repository
- ✓Version-controlled — pipeline changes tracked in Git
- ✓Supports complex workflows: stages, parallel execution, approvals
- ✓Two types: Declarative (recommended) and Scripted (flexible but complex)
Declarative Pipeline
GROOVY
// Jenkinsfile (in root of repository)
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/org/repo.git'
}
}
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh './scripts/deploy.sh'
}
}
}
post {
success {
echo 'Pipeline passed!'
}
failure {
mail to: 'team@company.com', subject: 'Build Failed', body: 'Check Jenkins'
}
}
}
Comparison
| Feature | Freestyle | Pipeline |
|---|---|---|
| Configuration | Jenkins UI | Code (Jenkinsfile) |
| Version control | No | Yes (in Git) |
| Complex workflows | Limited | Yes (stages, parallel) |
| Reusability | No | Yes (shared libraries) |
| Code review | No | Yes |
| Parallel execution | No | Yes |
| Recommended for | Simple tasks | All CI/CD workflows |
