How do you create a pipeline in Jenkins?

Creating a Jenkins pipeline means defining the build, test, and deploy stages as code in a Jenkinsfile, which Jenkins executes automatically whenever changes are detected in the source repository.

Key Points

Example

A team adds a Jenkinsfile to the repo root with build, test, and deploy stages; after connecting a GitHub webhook, every push to main automatically triggers Jenkins to run mvn verify and then deploy the resulting artifact.

pipeline {
    agent any
    stages {
        stage('Checkout') { steps { checkout scm } }
        stage('Build')    { steps { sh 'mvn clean package' } }
        stage('Test')     { steps { sh 'mvn test' } }
        stage('Deploy')   { steps { sh './deploy.sh' } }
    }
}

Interview Tip

A concise interview answer is

I create a Pipeline job in Jenkins and define the stages in a Jenkinsfile checked into the repo, using declarative syntax for checkout, build, test, and deploy steps. Jenkins then triggers that pipeline automatically via a webhook whenever code is pushed.

Last updated: 16 July 2026

Previous question: What is your application deployment structure?

Next question: If a build in your Jenkins pipeline fails intermittently, what strategies would you implement to diagnose and fix the underlying issue?

More Deployments interview questions

All Deployments questions