Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在构建后杀死jenkins生成的子进程?_Node.js_Ant_Jenkins_Cmd - Fatal编程技术网

Node.js 如何在构建后杀死jenkins生成的子进程?

Node.js 如何在构建后杀死jenkins生成的子进程?,node.js,ant,jenkins,cmd,Node.js,Ant,Jenkins,Cmd,当我使用Jenkins构建我的项目时,我需要启动一个nodejs服务器进程来承载一些文件,如果我像下面这样启动这个进程,构建将无限挂起 <target name="staticserver" description="Starts nodejs static server"> <exec executable="node"> <arg value="${env.WORKSPACE}staticserver.js"/> </

当我使用Jenkins构建我的项目时,我需要启动一个nodejs服务器进程来承载一些文件,如果我像下面这样启动这个进程,构建将无限挂起

<target name="staticserver" description="Starts nodejs static server">
    <exec executable="node">
        <arg value="${env.WORKSPACE}staticserver.js"/>
    </exec>
</target>

因此,我切换到以下内容,构建将运行良好

<target name="staticserver" description="Starts nodejs static server">
    <exec executable="cmd.exe">
        <arg value="/c"/>
        <arg value="start"/>
        <arg value="node"/>
        <arg value="${env.WORKSPACE}staticserver.js"/>
    </exec>
</target>

但是,当Jenkins构建完成时,节点进程将保持活动状态

我四处搜索,但似乎每个人在杀死子进程时的问题是Jenkins杀死了所有的子进程

我应该如何启动节点进程,以便Jenkins可以在构建完成后正确地终止它? 我是否从错误的角度看待这个问题,需要从不同的角度看待它


谢谢。

我找到了两种解决问题的方法第一种是添加一个杀死所有node.exe的目标,如果没有其他节点实例需要在同一台机器上运行,就不会有问题

<target name="stopnode" description="Stops all instances of node">
    <exec executable="taskkill">
        <arg value="/IM"/>
        <arg value="node.exe"/>
    </exec>
</target>

global.timer = {
    count: 5,
    reset: function() {
        this.count = 5;
    }
};

function countdown() {
    global.timer.count = global.timer.count - 1;
    //console.log(global.timer.count);
    if (global.timer.count <= 0) {
        clearInterval(cd);
        process.exit(0);
    }
}

var cd = setInterval(function () { countdown() }, 1000);