DevOps Classroom Series – 01/Oct/2020

Scripted Syntax vs Declarative Syntax

  • Style:
    • Scripted syntax is imperative
    • Declrative Syntax is declarative
  • Scripting:
    • Scripted: Uses Groovy lanugage constructs
    • Declarative: Jenkins DSL
  • UI Tooling
    • Declarative: Blue Ocean
  • Example:
    • Scripted:
      node('HMS') {
          stage ('git') {
              git 'https://github.com/dummygitrepos/gameoflife.git'
          }
          stage ('compile'){
              sh 'mvn package'
          }
      }
      
    • Declarative:
      pipeline {
          agent { label 'HMS' }
          stages {
              stage ('SCM') {
                  steps {
                      git 'https://github.com/dummygitrepos/gameoflife.git'
                  }
              },
              stage ('Compile') {
                  steps {
                      sh 'mvn package'
                  }
              } 
          }
      }
      

Scripted Syntax

  • node: This line tells jenkins on which node it should run this part of pipeline
    • syntax:
      • node(‘HMS’)
      • node (‘HMS && QA’)
    • Then node will have a closure {} Preview
  • stage:
    • This is also a closure will allows to run the steps
    • Should have a name.
  • steps:
    • Jenkins DSL Commands are referred as steps.
    • This is lowest/atomic level of functionality defined by the DSL.
    • Refer Here for all the available steps
    • Now lets look at git steps and understand different ways of defining a step
      • Navigate to git the above link Preview
      • Refer the docs from here
      • Every step has arguments
      • Different versions of git step
      1. git 'https://github.com/dummygitrepos/gameoflife.git'
      2. git url: 'https://github.com/dummygitrepos/gameoflife.git', branch: 'master'
      
  • Relation b/w node stage and steps are as shown below Preview

Declarative Pipeline Structure

  • The Structure is represented below Preview
  • Refer Here for declarative pipeline
  • Agents in pipeline: Refer Here
    • Example syntax
      pipeline {
          agent { label 'HRMS && QA'  }
      }
    

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube