Jenkins Pipeline Setup for Test Automation
Hope you guys are doing good. This is a small bit of my experiences while configuring test automation with continuous integration.
Initial need :
My need was to find a way to run a
- Performance Test (Jmeter)
- UI automation Test (Robot)
- Send an Email
As a solution, I used Jenkins Pipeline to achieve my goal. There might be a lot of other areas that you can use, but with some simple, common methods you can build a Jenkins pipeline script.
These are the pipeline concepts that I have used
Node :
A node is a machine which is part of the Jenkins environment and is capable of executing a Pipeline.
Stage :
A Stage block defines a conceptually distinct subset of tasks performed through the entire Pipeline (e.g. "Build", "Test" and "Deploy" stages), which is used by many plugins to visualize or present Jenkins Pipeline status/progress.
Dir(<Your directroy>){} :
Specifying a directory that you want to execute a specific task
P.s There are many other concepts like Step, etc. I did not use them
For the Local Jenkins Config, My Pipeline script is planned like this.
node{
stage('This Stage will execute the Performance Test and Publish The Report')
dir(""){
bat 'jmeter -Jjmeter.save.saveservice.output_format=xml -n -t <JmeterFile>.jmx -l <ReportLocation>.jtl'
perfReport sourceDataFiles: '<ReportLocation>.jtl', compareBuildPrevious: true
}
stage('This will run the Robot Framework Test'){
dir("Robot Test Automation Directroy") {
bat 'robot <Robot Script>.robot'
}
}
stage('Email Test'){
emailext attachmentsPattern: dir("<Attach Folder Path>"){"**/*"} ,
body: '<Body Test>',
subject: '<Subject>',
to: '<To Email>'
}
stage('This will run the Robot Framework Test'){
dir("Robot Test Automation Directroy") {
bat 'robot <Robot Script>.robot'
}
}
stage('Email Test'){
emailext attachmentsPattern: dir("<Attach Folder Path>"){"**/*"} ,
body: '<Body Test>',
subject: '<Subject>',
to: '<To Email>'
}
}
bat command is used since I'm using Windows. If you are using Linux, you need to go with Sh
The main structure you need to understand in the pipeline is
node{
stage('Name of the Stage'){
<Code to Execute>
}
stage('Name of the Stage'){
<Code to Execute>
}
}
You can define as much as stages you need. If a stage failed in the middle the build will fail without moving to other stages. If you need it to continue if a stage in the middle got failed, you need to use 'try catch' in the node script.
For more information about the pipeline concept refer to this link: https://jenkins.io/doc/book/pipeline/
bat command is used since I'm using Windows. If you are using Linux, you need to go with Sh
The main structure you need to understand in the pipeline is
node{
stage('Name of the Stage'){
<Code to Execute>
}
stage('Name of the Stage'){
<Code to Execute>
}
}
You can define as much as stages you need. If a stage failed in the middle the build will fail without moving to other stages. If you need it to continue if a stage in the middle got failed, you need to use 'try catch' in the node script.
For more information about the pipeline concept refer to this link: https://jenkins.io/doc/book/pipeline/
Comments
Post a Comment