First We need to create pipeline project
Then configuration-> Pipeline -> Select pipeline script
And add pipeline script.
------------------------------------------ Local Machine pipeline script-------------------------------------
Ex. script ( Working directory from local machine )
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "MAVEN_HOME"
}
stages {
stage('Compile') {
steps {
dir("/Users/apple/Desktop/Demo/BDDCucumber_RestAssured_APIFramework") {
sh "mvn compile"
}
}
}
stage('Testing') {
steps {
dir("/Users/apple/Desktop/VaibhavDemo/BDDCucumber_RestAssured_APIFramework") {
sh "mvn test"
}
}
}
stage('Reporting') {
steps {
dir("/Users/apple/Desktop/VaibhavDemo/BDDCucumber_RestAssured_APIFramework") {
cucumber failedFeaturesNumber: -1, failedScenariosNumber: -1, failedStepsNumber: -1,
fileIncludePattern: 'cucumber.json', jsonReportDirectory: 'target', pendingStepsNumber: -1,
skippedStepsNumber: -1, sortingMethod: 'ALPHABETICAL', undefinedStepsNumber: -1
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: '',
reportFiles: 'report/maven-JVM-report/Maven-Extent-Reports/Extent-Report.html',
reportName: 'Extent_Report', reportTitles: ''])
}
}
}
stage('Mailing') {
steps {
dir("/Users/apple/Desktop/Demo/BDDCucumber_RestAssured_APIFramework") {
emailext attachLog: true, attachmentsPattern: 'report/maven-JVM-report/Maven-Extent-Reports/Extent-Report.html', body: '''Hello Team,
Please find below CICD Job execution details,
Thanks,
Automation Team
''', subject: '${JOB_NAME}, ${BUILD_STATUS}, Build #${BUILD_NUMBER}', to: 'qauser@gmail.com'
}
}
}
}
post {
always {
dir("/Users/apple/Desktop/VaibhavDemo/BDDCucumber_RestAssured_APIFramework") {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true,
reportDir: 'report/maven-JVM-report/Maven-Extent-Reports', reportFiles: 'Extent-Report.html',
reportName: 'Blue_Ocean_Test_Report', reportTitles: ''])
}
}
}
}
----------------------------------------- Git Pipeline Script-------------------------------------
Ex. script ( Working directory from Repo ex. GitHub)
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "MAVEN_HOME"
}
stages {
stage('Compile') {
steps {
// Get some code from a GitHub repository
git branch: 'develop_ios', credentialsId: '2', url: 'https://test@bitbucket.org/demo/script.git'
// Run Maven on a Unix agent.
sh "mvn compile"
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
stage('Testing') {
steps {
// Get some code from a GitHub repository
git branch: 'develop_ios', credentialsId: '2', url: 'https://test@bitbucket.org/demo/script.git'
// Run Maven on a Unix agent.
sh "mvn verify"
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
stage('Reporting') {
steps {
cucumber failedFeaturesNumber: -1, failedScenariosNumber: -1, failedStepsNumber: -1,
fileIncludePattern: 'cucumber.json', jsonReportDirectory: 'target', pendingStepsNumber: -1,
skippedStepsNumber: -1, sortingMethod: 'ALPHABETICAL', undefinedStepsNumber: -1
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false,
reportDir: '', reportFiles: 'report/TestNG_Report/Report/iOS_Testing_Report.html',
reportName: 'KASH iOS Test Report', reportTitles: ''])
}
}
stage('Mailing') {
steps {
emailext attachLog: true, attachmentsPattern: 'report/TestNG_Report/Report/iOS_Testing_Report.html',
body: '''Hello Team,
Please find below CICD Job execution details,
Thanks,
Automation Team
''', subject: '${JOB_NAME}, ${BUILD_STATUS}, Build #${BUILD_NUMBER}', to: 'qauser@gmail.com'
}
}
}
post {
always {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true,
reportDir: 'report/TestNG_Report/Report', reportFiles: 'iOS_Testing_Report.html',
reportName: 'Blue Ocean Test Report',
reportTitles: ''])
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false,
keepAll: true, reportDir: 'report/TestNG_Report/JVM_Report/cucumber-html-reports',
reportFiles: 'overview-features.html',
reportName: 'Blue Ocean JVM Test Report', reportTitles: ''])
}
}
}