Failed to restart tomcat in jenkins

Recently, I have done continuous integration of jenkins+Git+tomcat. In the process again, I use ansible to perform remote server operations. When restarting tomcat, it always fails. I use a script to close tomcat and start tomcat.
Failed to restart tomcat in jenkins

1. Check the output information as above, the return value is not zero. It turns out that during the execution process, if the return value is not zero, jenkins considers it to fail and does not proceed further.
2. There is another problem. When the execution is successful on jenkins, tomcat cannot be started, which is very troublesome.

After trial and error, it turns out that the following method should be used:
[root@localhost target]# cat /etc/ansible/roles/jenkins_test.yml

  • hosts: web1
    tasks:

    • name: crontab echo
      cron: name=check minute=5 job='echo 123 >>/tmp/jenkins'
    • name: copy war
      copy: src=/root/.jenkins/workspace/wwwww/se-service-datareceive/target/se-service-datareceive.jar backup=yes dest=/tmp
    • name: copy html
      copy: src=/etc/ansible/html/456.html dest=/home/tomcat_zfltest_8180/webapps/docs
    • name: add group
      group: name=jenkins gid=666 state=present system=yes
    • name: add user
      user: name=jenkins group=jenkins uid=555 state=present
    • name: tomcat_123.html
      shell: echo "<p>" >> /home/tomcat_zfltest_8180/webapps/docs/123.html && date >> /home/tomcat_zfltest_8180/webapps/docs/123.html && echo "</p>" >> /home/tomcat_zfltest_8180/webapps/docs/123.html
    • name: stop tomcat
      shell: ps -ef|grep tomcat_zfltest_8180|grep -v grep |awk '{print $2}'|xargs sudo kill -9 >> /dev/null 2<&1 || echo 0
    • name: start tomcat
      shell: cd /home/tomcat_zfltest_8180/bin/ && sudo nohup sh startup.sh &


      When closing tomcat, note that the return value is not zero when it has been closed, and needs to be processed.
      On startup, nohup is required.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324735945&siteId=291194637