如何在 Jenkins 中分叉后台进程?设置 BUILD_ID 并使用 nohup 似乎不起作用 [英] How to fork a background process in Jenkins? Setting BUILD_ID and using nohup seems to be non working

查看:36
本文介绍了如何在 Jenkins 中分叉后台进程?设置 BUILD_ID 并使用 nohup 似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Jenkins(版本 1.578)有一份 Maven 工作.下面的 maven 代码段(用 Groovy 代码编写的 Ant 脚本)启动了一个 Fuse 服务器,我不能让 Jenkins 在作业完成后让它继续运行.

I have a maven job in Jenkins(version 1.578). The maven snippet (Ant script written in Groovy code) below starts a Fuse server, and I cannot make Jenkins to leave it running after the job finishes.

<profile>
    <id>start-fuse</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-fuse</id>
                        <phase>integration-test</phase>
                        <goals>
                          <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                            <![CDATA[
                                def fuseBinDirectory = '${fuse.dir}/bin'
                                ant.exec(executable:'bash', dir:fuseBinDirectory, failonerror:true, osfamily:'unix') {
                                    ant.env(key:'BUILD_ID',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
                                    ant.env(key:'KARAF_OPTS',value:'${KARAF_OPTS}')
                                    ant.arg(value:"-c")
                                    ant.arg(value:"nohup ./start ${fuse.start.parameters} </dev/null >> nohup.out 2>&1&")
                                }
                            ]]>
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

我做错了什么?

如何在 Windows 下 fork 一个类似的 Fuse 进程,让 Jenkins 不会杀死它?

How can I fork a similar Fuse process under Windows so that Jenkins does not kill it?

添加接受的答案中提到的 4 个 env 条目适用于 Windows 和 Linux.因此,无论您拥有哪种工作类型,您都可以拥有以下内容:

Adding the 4 env entries mentioned in the accepted answer works both on windows and linux. So no matter which job type you have you can have something like this:

ant.exec(executable:'sh', dir:fuseBinDirectory, failonerror:true, osfamily:'unix') {
    ant.env(key:'BUILD_ID',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
    ant.env(key:'HUDSON_SERVER_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
    ant.env(key:'JENKINS_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
    ant.env(key:'JENKINS_SERVER_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
    ant.env(key:'HUDSON_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
    ant.env(key:'KARAF_OPTS',value:'${KARAF_OPTS}')
    ant.arg(line:'-c "./start ${fuse.start.parameters}"')
}

Nohup 似乎完全没有必要.

Nohup seems to be non neccessary at all.

推荐答案

如果您注意到 这个 页面,您会注意到,在使用自由式模板创建的作业的情况下,BUILD_ID 确实有效.还有许多其他人面临类似的问题.只有在非自由式工作时才会出现此类问题.

If you will notice the comment by user 'mdp' in this page, you will notice that in case of jobs created using freestyle template, BUILD_ID does work. There are many others who faced similar issue. Such issues were seen only when it was a non-freestyle job.

或者,还应检查取消设置以下变量:HUDSON_COOKIE、HUDSON_SERVER_COOKIE、JENKINS_COOKIE 或 JENKINS_SERVER_COOKIE,如 这个链接.

Alternatively, should also check unsetting the following variables: HUDSON_COOKIE, HUDSON_SERVER_COOKIE, JENKINS_COOKIE or JENKINS_SERVER_COOKIE as suggested by few (Comments section) in this link.

这篇关于如何在 Jenkins 中分叉后台进程?设置 BUILD_ID 并使用 nohup 似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆