</>

Technology

Jenkins

Difficulty

Beginner

Interview Question

What is the difference between Freestyle and Pipeline jobs in Jenkins?

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

FeatureFreestylePipeline
ConfigurationJenkins UICode (Jenkinsfile)
Version controlNoYes (in Git)
Complex workflowsLimitedYes (stages, parallel)
ReusabilityNoYes (shared libraries)
Code reviewNoYes
Parallel executionNoYes
Recommended forSimple tasksAll CI/CD workflows

Follow AutomateQA

Related Topics