我已经创建了一个剧本来复制 tomcat 包、更改端口并从我的构建中复制 .war,并将其部署在 tomcat 服务器中并启动 tomcat 服务。当我从终端执行我的剧本时,它运行良好并且 tomcat 服务已启动。
但是当我从 Jenkins 调用剧本时,它完成了除启动 tomcat 服务之外的所有任务,尽管 Jenkins 显示已更改。我提供了简单的剧本和 Jenkins 控制台输出。
控制台输出:
[INFO] Finished at: 2019-02-15T20:13:46+05:30
[INFO] Final Memory: 27M/214M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /var/lib/jenkins/workspace/ILP2_Clean_Pkg/Bookstore/ILP_Bookstore/pom.xml to devops.ilp1/ILP/0.0.1-SNAPSHOT/ILP-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /var/lib/jenkins/workspace/ILP2_Clean_Pkg/Bookstore/ILP_Bookstore/target/ILP_Bookstore.war to devops.ilp1/ILP/0.0.1-SNAPSHOT/ILP-0.0.1-SNAPSHOT.war
channel stopped
[ILP2_Clean_Pkg] $ sshpass ******** /usr/bin/ansible-playbook /var/lib/jenkins/roles/tomcat/main.yaml -i /var/lib/jenkins/ansiserver -f 5 -u jenkins -k
PLAY [localhost] ***************************************************************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [/var/lib/jenkins/roles/tomcat : to unarchive tar tomcat] *****************
changed: [localhost]
TASK [/var/lib/jenkins/roles/tomcat : to change port number] *******************
changed: [localhost]
TASK [/var/lib/jenkins/roles/tomcat : to copy the war source file] *************
ok: [localhost]
TASK [/var/lib/jenkins/roles/tomcat : to add tomcat users] *********************
changed: [localhost]
TASK [/var/lib/jenkins/roles/tomcat : to start tomcat services] ****************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=6 changed=4 unreachable=0 failed=0
ILP2_BookStore is disabled. Triggering skipped
ILP2_Inttesting_Scan is disabled. Triggering skipped
Finished: SUCCESS
剧本
cat /var/lib/jenkins/roles/tomcat/main.yaml
- hosts: localhost
become: yes
become_user: jenkins
roles:
- /var/lib/jenkins/roles/tomcat
root@:/etc/systemd# cat /var/lib/jenkins/roles/tomcat/tasks/main.yaml
- name: to unarchive tar tomcat
unarchive:
src: apache-tomcat-8.5.38.tar.gz
dest: "{{tomcat}}"
- name: to change port number
template:
src: server.xml.j2
dest: "{{tomcat}}/apache-tomcat-8.5.38/conf/server.xml"
- name: to copy the war source file
copy:
src: /var/lib/jenkins/workspace/ILP_BookStore/target/ILP_Bookstore.war
dest: "{{tomcat}}/apache-tomcat-8.5.38/webapps/"
- name: to add tomcat users
template:
src: tomcat-users.xml.j2
dest: "{{tomcat}}/apache-tomcat-8.5.38/conf/tomcat-users.xml"
- name: to start tomcat services
shell: "{{tomcat}}/apache-tomcat-8.5.38/bin/startup.sh"
root@:/etc/systemd# cat /var/lib/jenkins/roles/tomcat/vars/main.yaml
tomcat: /home/osgdev/ansilab/tomcat/
tomcat_port: 12345
root@:/etc/systemd# ls -ld /var/lib/jenkins/roles/tomcat/vars/files/
ls: cannot access '/var/lib/jenkins/roles/tomcat/vars/files/': No such file or directory
root@:/etc/systemd#
答案1
这可能是由于Jenkins 进程树杀手。TL;DR:除非禁用进程树杀手,否则 Jenkins 构建启动的守护进程或其他长寿命后台进程将在该构建完成时被终止。
要禁用进程树杀手,请按照我链接到您的文档中的说明进行操作。根据您在问题中发布的信息,我认为禁用它的最佳方法是BUILD_ID
在启动任何守护进程之前更改环境变量。