To complete the tasks and set up continuous integration (CI) with Jenkins, Git, GitHub, and Maven for the RestAssured project, follow the steps outlined below. These steps include running tests in both Eclipse and command-line, pushing code to GitHub, and setting up Jenkins to run the tests.
- Open Eclipse and ensure you have Maven installed in your IDE.
- Right-click on the project (RestAssured Project) in the "Project Explorer."
- Navigate to Run As -> Maven Test.
This will execute the tests defined in the pom.xml using the TestNG suite.
- Open the Command Prompt.
- Navigate to the project directory:
cd C:\Users\pravin\restAssuredTraining\PetStoreAutomation
- Run the tests using the Maven command:
mvn clean test
This will execute the tests specified in the pom.xml.
- Navigate to your project folder:
cd C:\Users\pravin\restAssuredTraining\PetStoreAutomation
- Initialize the local repository (if not already done):
git init
- Configure Git username and email:
git config --global user.name "your name" git config --global user.email "abc@gmail.com"
- Add all files to the staging area:
git add -A
- Commit your changes:
git commit -m "Initial commit with RestAssured project"
- If the repository is not linked to GitHub, add the remote URL:
git remote add origin https://github.com/pravin234/Rest_Assure_Framework_Project_PetDemo.git
- Push the code to GitHub:
git push -u origin master
If prompted, provide your GitHub credentials or set up a personal access token.
- Jenkins is installed.
- Git is installed.
- A repository exists on GitHub https://github.com/pravin234/Rest_Assure_Framework_Project_PetDemo.git
-
Install Git and Maven Plugins in Jenkins:
- Open Jenkins in your browser.
- Go to Manage Jenkins -> Manage Plugins.
- Install the Git plugin and Maven Integration plugin.
-
Create a Jenkins Job:
- Go to Jenkins Dashboard.
- Click on New Item.
- Select Freestyle Project and name it (e.g.,
RestAssuredCI). - Click OK.
-
Configure Source Code Management:
- In the Jenkins job configuration, under Source Code Management, choose Git.
- Add your repository URL:
https://github.com/pravin234/Rest_Assure_Framework_Project_PetDemo.git - Add credentials (GitHub username and password or personal access token).
-
Set up Build Triggers:
- Scroll to the Build Triggers section.
- Check GitHub hook trigger for GITScm polling to allow Jenkins to automatically trigger builds when new commits are pushed to GitHub.
-
Add Maven Build Step:
- In the Build section, click on Add build step -> Invoke top-level Maven targets.
- In the Goals field, enter:
clean test
-
Save and Build the Job:
- Save the job configuration.
- You can now trigger the build manually by clicking Build Now, or it will be triggered automatically if the webhook is set up.
- In GitHub, go to your repository settings.
- Navigate to Webhooks -> Add webhook.
- Add the Jenkins webhook URL (e.g.,
http://your-jenkins-url/github-webhook/). - Jenkins will now automatically trigger a build whenever you push new code to GitHub.
-
Install Git: Make sure you have Git installed and configured on your system.
-
Create GitHub Account & Repository:
- If you haven't already, create a GitHub account.
- Create a new repository for your project (e.g.,
PetStoreAutomation).
-
Configure Git:
- Initialize the local repository (
git init). - Add your project files using
git addand commit usinggit commit.
- Initialize the local repository (
-
Push Code to GitHub:
- Add the remote GitHub repository using
git remote add origin. - Push the local commits to GitHub using
git push.
- Add the remote GitHub repository using
-
Set Up Jenkins:
- Install and configure Jenkins with Git and Maven plugins.
- Create a job in Jenkins that pulls code from GitHub, builds the project, and runs the tests.
- Trigger the job via webhooks when new code is pushed to GitHub.
By following these steps, you can successfully set up continuous integration for your RestAssured project with Git, GitHub, and Jenkins. This setup will allow you to automatically run your test suite every time new code is pushed to the repository.