Sunday, 29 May 2022

Ansible Playbook | Trigger Jenkins Job using token and copy .war to Apache tomcat path

 cat trigger_jenkins.yml 
---
 - name: Deployment of .war file
   hosts: localhost
   become: yes

   tasks:

      - name: Trigger Jenkins Job
        shell: curl -v -X POST http://localhost:8080/job/Project_name/build --user jenkinsxyz:110d44acb43a8f57c8e54fc6360bf3e5ab

      - name: Wait until the file .war is present before continuing
        wait_for:
          path: /var/lib/jenkins/workspace/Project_name/target/Name.war

     - name: copy .war file to tomcat
        copy:
          src: /var/lib/jenkins/workspace/Project_name/target/Name.war
          dest: /opt/tomcat10/apache-tomcat-10.0.21/webapps/
          remote_src: yes
          directory_mode: yes

No comments:

Post a Comment