Ravindra BagaleCourses & study guides

Chapter 10: Jenkins Introduction

10.4 Declarative Jenkinsfile basics

Commit a Jenkinsfile at the repo root (or a path you configure):

// Jenkinsfile — Declarative sketch for badge API tests
pipeline {
  agent any

  options {
    timestamps()
  }

  stages {
    stage('Checkout') {
      steps {
        checkout scm
      }
    }

    stage('Test') {
      steps {
        sh 'pytest -q'
        // Node sketch: sh 'npm ci && npm test'
      }
    }

    stage('Build image') {
      when {
        branch 'main'
      }
      steps {
        sh 'docker build -t badge-api:${GIT_COMMIT} .'
      }
    }
  }

  post {
    always {
      echo "Build finished with status: ${currentBuild.currentResult}"
    }
  }
}
Block Role
pipeline { } Declarative root
agent Where to run (any, label, or docker agent)
stages / stage Named conveyor sections
steps Actual commands
when Conditional stage
post Always / success / failure hooks

Scripted Pipeline (older free-form Groovy) still exists. Prefer Declarative as a beginner — clearer structure, closer to how you explain stages in interviews.

Ravindra Bagale's Tip

Freestyle madhe commands click-click — review nahi hote. Jenkinsfile Git madhe theva; PR var pipeline change disava. Bilkul visru naka!