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'
}
}
}
}
Like this:
Like Loading...