简体   繁体   English

从詹金斯开始和停止一个罐子

[英]starting and stopping a jar from jenkins

I've been working on my jenkins server off and on for the last few weeks. 在过去的几周里,我一直在不停地运行我的jenkins服务器。 Right now it runs fine building and outputting the files to a remote location. 现在,它运行良好,并且可以将文件输出到远程位置。 However, i'm looking to do some pass or fail tests on the files before they are uploaded. 但是,我希望在上传文件之前对文件进行通过或失败测试。 This way i avoid releasing broken versions of my work. 这样,我避免发布我的作品的损坏版本。 As well avoid more bug reports that i do not need to be reading. 以及避免更多我不需要阅读的错误报告。

The files i'm looking to run are actually plugins for another program. 我要运行的文件实际上是另一个程序的插件。 So i need to actually start this program as i can configure all the files before hand. 所以我需要实际启动该程序,因为我可以手动配置所有文件。 The program is a .jar file which i know i can launch using a bat of shell script. 该程序是一个.jar文件,我知道我可以使用一连串的shell脚本启动。 The issue is i don't know at this point how to terminate the .jar program after it has been running. 问题是我现在不知道如何在运行后终止.jar程序。 All the solutions i've found require me to modify the jar to terminate itself, or kill the JVM. 我找到的所有解决方案都需要我修改jar才能终止自身,或者杀死JVM。 Both i can't due for varies reasons. 由于种种原因,我俩都不能。

It's a heavy hack, but you can make a shell script start a background thread that checks if the JVM is done, then terminate it. 这是一个沉重的hack,但是您可以使shell脚本启动一个后台线程,该线程检查JVM是否完成,然后终止它。

Rudimentary example in bash: bash的基本示例:

start_jvm_command >>console.log 2>&1 </dev/null &
while ! grep 'done signal' console.log; do sleep 1; done
pkill -f "regexp for start_jvm_command"

Note: I was using pkill to terminate to avoid wrapper shell scripts. 注意:我使用pkill终止以避免包装程序外壳脚本。

It been a year since i asked this question but i found a much nicer way to solve this question. 自问这个问题已经一年了,但是我找到了解决这个问题的更好的方法。 Its called JUnit and is a testing lib for java. 它称为JUnit,是Java的测试库。 With it i don't need to launch the entire jar but can test peace by peace at a time. 有了它,我不需要启动整个罐子,而是可以一次一次地测试和平。 As well if require i can write a test to launch the entire .jar file. 如果需要,我也可以编写一个测试来启动整个.jar文件。 In the test i can check if files exist, if functions complete correctly, and if any error is thrown during runtime. 在测试中,我可以检查文件是否存在,功能是否正确完成以及在运行时是否抛出任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM