Need For Pipelines
- Consider a Repository (https://github.com/GitPracticeRepo/spring-petclinic) where there are multiple branches and User is expected to create multiple projects for building each branch.
- To achieve this we create multiple projects every time manually configuring the options
- For master branch, you are supposed to do clean build (mvn clean package) and sprint-1 branch incremental build (mvn package)
Jenkins Pipeline
- Is a scripted way of defining jenkins job.
- Jenkins job can be defined in git repository in one file.
- Lets try this.
- Navigate to code repository and create a file Jenkinsfile with following content
node {
stage('SCM') {
// git clone
git 'https://github.com/GitPracticeRepo/spring-petclinic.git'
}
stage ('build the packages') {
// mvn package
sh 'mvn package'
}
stage ('archival') {
// archiving artifacts
archive 'target/*.jar'
}
}
- Now open Jenkins and create a pipeline project as shown below
- In Jenkins Pipeline the script is written by using groovy language (Java Based Language) with this we get the following benefits
- Customization of builds become simpler
- Creating reusable build library is possible
- Even in the case of plugins what we generally call from Script is functions.