DevOps Classroomnotes 03/Mar/2023

Declarative Pipelines

  • Jenkins has a DSL (Domain Specific Language) for creating Declarative Pipeines
  • Jenkins Pipeline Syntax official docs Refer Here
  • Lets build a game of life declrative pipeline
pipeline {
    agent { label 'MAVEN_JDK8' }
    stages {
        stage('vcs') {
            steps {
                git url: 'https://github.com/khajadevopsmarch23/game-of-life.git',
                    branch: 'declarative'
            }
        }
        stage('package') {
            steps {
                sh 'mvn package'
            }
        }
        stage('post build') {
            steps {
                archiveArtifacts artifacts: '**/target/gameoflife.war',
                                 onlyIfSuccessful: true
                junit testResults: '**/surefire-reports/TEST-*.xml'
            }
        }
    }
}
  • Refer Here
  • Build the project and view the results
  • Exercise: Create a pipeline with 3 stages
    • vcs:
      • run the command git --version
      • should run on agent with label ‘git’
    • build
      • run the command mvn --version
      • should run on agent with label ‘maven’ or ‘maven-jdk8’
    • deploy
      • run the command kubectl --version
      • should run on agent with label ‘k8s’ and ‘developer’
  • Solution
pipeline {
    agent none
    stages {
        stage('vcs') {
            agent { label 'GIT' }
            steps { 
                sh 'git --version'
            }
        }
        stage('build') {
            agent { label 'MAVEN || MAVEN_JDK8' }
            steps {
                sh 'mvn --version'
        }
        stage('deploy') {
            agent { label 'k8s && developer' }
            steps {
                sh 'kubectl --version'
            }
        }
    }

}
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

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

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Exit mobile version
%%footer%%