Jenkins pipeline integration helps automate running your Selenium Java tests. It makes testing faster and easier by running tests automatically when you change your code.
You want to run Selenium tests automatically after every code change.
You need to see test results in one place without running tests manually.
You want to run tests on different machines or environments automatically.
You want to combine building your Java project and testing in one process.
You want to get notified if tests fail or pass after code updates.
Syntax
Selenium Java
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
}
}
pipeline defines the whole process.
agent any means run on any available machine.
Examples
This simple pipeline runs only the test stage using Maven.
Selenium Java
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'mvn test'
}
}
}
}
This pipeline builds, tests, and saves the built files as artifacts.
5. How can you modify a Jenkins pipeline to run Selenium Java tests only if the build stage succeeds, and always archive test reports regardless of test results?
hard
A. Use 'when' condition to skip archiving if tests fail
B. Run tests in parallel with build stage and archive in 'failure' block
C. Skip build stage and run tests directly, archive in 'success' block
D. Use 'post' block with 'always' to archive reports and normal stages for build and test
Solution
Step 1: Ensure test stage runs after successful build
By default, stages run sequentially; test stage runs only if build succeeds.
Step 2: Use 'post' block with 'always' to archive reports
The 'post' block with 'always' runs regardless of test success or failure, ensuring reports are archived.
Final Answer:
Use 'post' block with 'always' to archive reports and normal stages for build and test -> Option D
Quick Check:
Sequential stages + post always archive = D [OK]
Hint: Use post { always { ... } } to archive reports every run [OK]
Common Mistakes:
Running tests in parallel with build
Archiving only on success or failure
Skipping build stage before tests
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.