Jenkins 2.0
- Jenkins 2.0 Was a release to include pipeline as a code.
- Earlier Jenkins released Scripted Pipelines and then Declarative Pipelines.
- Scripted Pipeline:
- This is groovy language which we use in the scripted pipeline
- This is extreemly customizable
- Declarative Pipeline:
- This has jenkins DSL (Domain Specific Language) which is developed in groovy
- This is optimized around most of the ci/cd pipelines.
Groovy
- Groovy is a Java Based Language Refer Here
- Groovy is popular for simplicity and used for creating Domain Specific Languages and scripting purposes.
Scripted Pipelines
- The Structure of the Pipeline is as follows
- The Sample Jenkinsfile created has the following content
node {
stage('test') {
sh 'echo hello'
}
}
- Refer Here for the steps
- Refer Here for the changes done which was written based on a step called as git Refer Here
Declarative Pipelines
- These were created for the users who are familiar with jenkins to create pipelines without too much of learning curve.
- Refer Here
- The syntax overview
- In the Scripted Pipeline we have used the following
node {
stage('test') {
sh 'echo hello'
}
stage('learning') {
git url: 'https://github.com/GitPracticeRepo/game-of-life.git',
branch: 'master'
}
}
- Now lets try doing this in Declarative Refer Here for the changeset containing the declarative pipeline
pipeline {
agent any
stages {
stage('test') {
steps {
sh 'echo hello'
}
}
stage('learning') {
steps {
git url: 'https://github.com/GitPracticeRepo/game-of-life.git',
branch: 'master'
}
}
}
}
- Lets run stage test on any node and stage learning on a node with some label
OPENJDK-11-MAVEN
. Refer Here for the changes done
Environmental Variables in Jenkins
- On the node we will have some Environmental variables set by Operating system. In addition to that, Jenkins adds some environment variables which will contain information about the Jenkins project, job, git, build, etc..
Exercise
- Create a Jenkins JOb to build spring petclinic using maven
- free style project
- scripted pipeline
- declarative pipeline