Setup Jenkins Job to Execute Automation Tests
This blog will help you set up automation test jobs on Jenkins, providing a step-by-step guide or tutorial to streamline your development process with ease.
Jenkins
Server or VM
Jenkins "Master" node
Server or VM
Slave Agent "Slave" node
Prerequisites
- Jenkins Installed & operational.
- Automation Test Code for sample test.
- GitHub repository details for automation test code.
Steps To Configure Jenkins Job:
Open your Jenkins dashboard in a web browser and log in.
Create a New Item
Click on "New Item" on the Jenkins dashboard. Enter a name for your job, like "LaunchWebsiteJob". Select "Freestyle project" and click "OK".
Enter an item name
Freestyle project
Classic, general-purpose job type that checks out from up to one SCM, executes build steps serially, followed by post-build steps like archiving artifacts and sending email notifications.
Pipeline
Orchestrates long-running activities that can span multiple build agents. Suitable for building pipelines and/or organizing complex activities that do not easily fit in free-style job type.
Multi-configuration project
Suitable for projects that need a large number of different configurations, such as testing on multiple environments, platform-specific builds, etc.
Configure General Settings
Scroll down to the "General" section. Optionally, you can provide a description for your job. You can also restrict where this project can be run, but leaving it blank will allow it to run on any available agent.
Configure
Description
Configure Source Code Management (SCM)
If your website's source code is stored in a version control system like Git, you can configure the SCM here. Select your SCM option (e.g., Git). Enter the repository URL. You can also specify the branch to build if needed.
Configure
Source Code Management
Build Triggers
Configure Build Triggers
Scroll down to the "Build Triggers" section. Select how you want to trigger the build. For example, you can choose to build periodically or trigger the build remotely.
Configure
Build Triggers
Configure Build Steps
Scroll down to the "Build" section. Click on "Add build step" and select the appropriate build step for your website. For example: To run a pytest command, we can use below command
pytest -m=sanity --browser=chrome --url=https://www.smartspendops.com/ --headless=false --allureReport=true
Enter the necessary build commands or scripts.
Configure
Build Steps
Build Steps
Execute Windows batch command
Command
See the list of available environment variables
Configure Post-Build Actions
Scroll down to the "Post-build Actions" section. Procedure for adding Allure reports to the Jenkins Job.
Go to Jenkins dashboard. Select manage Jenkins.
Jenkins
+ New Item
People
Build History
Manage Jenkins
My Views
| S | W | Name |
|---|---|---|
| LaunchWebsiteJob |
Click on manage plugin. Search for the allure report in the available plugin.
Plugins
Allure 2.31.1
Build Reports
This plugin integrates Allure reporting tool into Jenkins.
Click on install without restart. Click on the global tools in Manage Jenkins > Tools. Select Allure Command line installations.
Allure Commandline installations
Add Allure CommandlineGive 'ALLURE_HOME' in the name. And the path of the allure folder in the installation directory and click on Save button.
Allure Commandline
Name
Installation directory
In job configuration select post-build action. Select allure report. Give the path of allure report in 'Path'.
Post-build Actions
Allure Report
Results:
Paths to Allure results directories relative from workspace. E.g. target/allure-results.
Path
Save your Jenkins Job Configuration
Click on "Save" to save your Jenkins job configuration.
Configure
Post-build Actions
Run the Jenkins Job
Click on "Build Now" to run your Jenkins job and launch your website.
Status
Changes
Workspace
Build Now
Configure
Delete Project
Rename
LaunchWebsiteJob
This Jenkins Job will navigate to the website
Permalinks
Build History
No builds
Monitor the Jenkins Job
Once the job is running, you can monitor its progress on the Jenkins dashboard.
Status
Changes
Console Output
View as plain text
Edit Build Information
Delete build #1
Console Output
Started by user Krishna Pukale Running as SYSTEM Building in workspace C:\Users\User\.jenkins\workspace\LaunchWebsiteJob [LaunchWebsiteJob] $ cmd /c call C:\Users\User\AppData\Local\Temp\jenkins7999765259831331340.bat C:\Users\User\.jenkins\workspace\LaunchWebsiteJob>start chrome https://www.smartspendops.com C:\Users\User\.jenkins\workspace\LaunchWebsiteJob>exit 0 Finished: SUCCESS
This is how you can configure a simple Jenkins Job to execute automation tests. Please feel free to reach out to me on krishna.pukale@refactorq.com if need any assistance in setting up a Jenkins Job for Automation Tests.
Cloud, DevOps & SRE Engineering
Standardise cloud environments, construct automated delivery pipelines, and establish production observability.