Monday, February 20, 2023

Jenkins Pipeline

 Scripted Pipeline:

  • Written in Groovy language
  • Provides a lot of power and flexibility
  • Allows for more complex pipeline structures and branching logic
  • Requires advanced knowledge of Groovy
  • Can be more challenging to maintain and manage
  • Uses imperative programming style with more code control and more verbose

Declarative Pipeline:

  • Written in a simpler, more structured syntax
  • Provides a simpler and more opinionated way of defining pipelines
  • Allows for easier error-checking and validation
  • Offers a simplified structure with less verbose code
  • Supports stage-level directives like when, parallel, input, and environment
  • Provides a more standardized structure that is easier to read and understand


Declarative Pipeline:
pipeline {
  agent any
  environment {
    DB_NAME = 'my_database'
    DB_USER = 'my_user'
    DB_PASS = 'my_password'
  }
  stages {
    stage('Build') {
      steps {
        sh 'mvn clean package'
      }
    }
    stage('Test') {
      steps {
        sh 'mvn test'
      }
    }
    stage('Deploy') {
      when {
        branch 'master'
      }
      steps {
        withCredentials([usernamePassword(credentialsId: 'my-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
          sh './deploy.sh ${DB_NAME} ${DB_USER} ${DB_PASS} ${USERNAME} ${PASSWORD}'
        }
      }
    }
  }
  post {
    always {
      cleanWs()
    }
    success {
      slackSend message: "Build Succeeded: ${currentBuild.fullDisplayName}", color: 'good'
    }
    failure {
      slackSend message: "Build Failed: ${currentBuild.fullDisplayName}", color: 'danger'
    }
  }
}

Jenkins Declarative and Scripted pipeline reference:

https://www.jenkins.io/doc/book/pipeline/

No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117