Back to All Questions
Question 98 of 100
CI/CD & DevOps
Advanced
Q98: How Do You Run API Tests in Jenkins? Step-by-Step.
🏗️Core Concept
How Do You Run API Tests in Jenkins? Step-by-Step.
Key Takeaways & Architecture Summary
- ✓Install the Node.js plugin and Newman package on the Jenkins server.
- ✓Configure a build pipeline stage to run Newman commands in the shell.
- ✓Publish JUnit test results to render interactive dashboards in Jenkins.
Direct Answer Summary
To run API tests in Jenkins, you install Newman on your Jenkins agent, configure a pipeline build stage to pull your collections, execute the test runner via the command line, and use the JUnit plugin to parse and display the test results.
⚠️ Senior Engineering Warning (Red Flag)
Do not ignore execution failures in Jenkins. Ensure that your shell commands exit with a non-zero code on test failure, which instructs Jenkins to mark the build stage as failed.
💡 STAR Architectural Explanation & Pro Tip
Automating report generation in Jenkins provides a historical dashboard of test status, allowing teams to track regression trends and compile times over multiple releases.
RestAssuredTest.java
Rest-Assured + Java// Jenkins Declarative Pipeline for automated API testing
stage('Execute API Regression') {
steps {
sh 'newman run Suite.json -e Staging.json --reporters junit --reporter-junit-export results.xml'
}
post {
always {
junit 'results.xml' // Renders interactive test report in Jenkins
}
}
}