Create Jenkins job using groovy script (Jenkins file)
Inside your project create a new file with name Jenkinsfile with below content:
Inside your project create a new file with name Jenkinsfile with below content:
pipeline {
agent any
stages {
stage ('Compile Stage') {
steps {
withMaven(maven : 'apache-maven-3.6.3') {
bat 'mvn clean compile'
}
}
}
stage ('Testing Stage') {
steps {
withMaven(maven : 'apache-maven-3.6.3') {
bat 'mvn test'
}
}
}
stage ('Install Stage') {
steps {
withMaven(maven : 'apache-maven-3.6.3') {
bat 'mvn install'
}
}
}
}
}
Push the code changes in Git.
Make sure maven name given in Jenkins Global Configuration should match with the Maven name in Jenkinsfile.
So, as you see in below screenshot, We have used the same maven name in Jenkins file also.
Now create a new Jenkins Pipeline Job, ensure that you have "Pipeline" plugin and "Pipeline Maven Integration" plugin is installed.
Job will look as below, Save the job and build, this will search for the Jenkinsfile and will perform all the stages which we have defined inside.
Once the execution is over, it will show all stages and so it becomes so easy for us for debugging in- case of any failures. This is all about pipeline.
Click on save.
And execute the job.
No comments:
Post a Comment