- Navigate to
Manage Jenkins > Global Tool Configuration
. - Under Maven, ensure you have a Maven installation configured. If not:
- Click Add Maven.
- Provide a name (e.g.,
Maven 3.8.6
). - Select "Install automatically" and choose the desired version.
- Click Save.
- On the Jenkins dashboard, click New Item.
- Enter the project name (e.g.,
Maven-Freestyle-Demo
). - Select Freestyle project and click OK.
- In the project configuration page:
- Under Source Code Management, select Git.
- Enter the repository URL of the Maven project (e.g.,
https://github.com/user/maven-sample.git
). - If the repository requires authentication, add credentials in Jenkins and select them here.
- Scroll to the Build section.
- Click Add build step and select Invoke top-level Maven targets.
- Configure the Maven build:
- Enter
clean install
in the Goals field. - Ensure the correct Maven installation is selected under Maven Version.
- Enter
- Scroll to the Post-build Actions section.
- Click Add post-build action and select Editable Email Notification.
- Configure the email settings:
- Enter a recipient email address in Project Recipient List (e.g.,
student@example.com
). - Optionally, customize the email subject and content template.
- Ensure Attach Build Log is checked if needed.
- Enter a recipient email address in Project Recipient List (e.g.,
- Click Advanced Settings to customize further, such as triggers (e.g., for success or failure).
- Click Add post-build action and select Archive the artifacts.
- Specify the files to archive in the Files to archive field:
- Example:
target/*.jar
to archive all JAR files generated in thetarget
directory.
- Example:
- Optionally, add patterns to exclude files if needed.
- Click Save to save the project configuration.
- On the project page, click Build Now to start a build.
- Monitor the build in the Build History section.
- Verify the build output:
- Check the build console logs for Maven build success.
- Ensure the specified artifacts are archived (visible under the build details).
- Confirm the email notification:
- Check the recipient's inbox for build success/failure notifications.
- Review the archived artifacts:
- Go to the specific build's details and ensure the artifacts are listed under Archived Artifacts.