1. Create a New Jenkins Job (Freestyle Project)

  1. Log into Jenkins: Open your browser and navigate to your Jenkins URL (e.g., http://localhost:8080).
  2. Create a New Job:

image.png


2. Configure Source Code Management (SCM)

Scroll to the "Source Code Management" Section:

image.png


3. Add Build Steps

  1. Scroll Down to the "Build" Section.

  2. Add the Maven Build Step: Click "Add build step" and select "Execute shell".

    Configure the Shell Command:

    To find the full path to your mvn executable on open terminal in Ubuntu and run:

    which mvn
    

    image.png

    The output will give you the full path (e.g., /usr/bin/mvn or /opt/maven/bin/mvn). Use this path in the command below in Jenkins Build Action Shell.

    #/path/to/your/maven/bin/mvn clean package
    # Example:
    /usr/bin/mvn clean package
    
  3. Add the Ansible Deployment Step: Click "Add build step" again and select "Execute shell" (or "Execute Windows batch command" on Windows).

    Configure the Shell Command: In the command box, add a command to trigger your Ansible playbook.

    Note: It is highly recommended to upload your hosts.ini and deploy.yml files to your GitHub repository alongside your project code. This simplifies referencing them in Jenkins and keeps your automation code version-controlled.

    If your files are in the root of your repository (follow this command if you are using given github link), the command would be:

    ansible-playbook -i hosts.ini deploy.yml
    

    If you are not storing them in GitHub, use the full paths:

    ansible-playbook -i /path/to/hosts.ini /path/to/deploy.yml
    

    Note:

image.png