本文介绍了node.js服务器未在詹金斯中给出成功状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jenkins运行一个nodejs项目.一切都进行得很好,除非我在詹金斯工作中看不到任何成功状态.

I want to use jenkins to run a nodejs project. All is going well except I do not see any success status in jenkins job.

我使用npm install&启动服务器. jenkins中的npm start命令.它启动了服务器,但是没有给构建成功,因此,我无法启动其他作业,这取决于节点服务器和服务器的构建成功.当新的提交到达时,jenkins会检测到它,但是该作业不会重新启动,而是在原始作业运行时保持待处理状态.

I started the server with npm install & npm start command in jenkins. It starts the server, but does not give build success, as a result, I can not start other jobs which depends on the build success of the node server & when a new commit arrives, jenkins detects it but the job does not restart rather remains at pending status as the original job is running.

我是詹金斯的新手.有人可以为此建议什么吗?

I am new to jenkins. can anyone suggest anything for that??

推荐答案

听起来像您的js脚本的执行会挂起您的构建,请尝试使用&之后将其发送到后台:

Sounds like the execution of your js script is hanging your build, try using a & after to send it to background:

npm install
npm start &

还要注意,从Jenkins作业运行npm start将产生一个新进程,并且 Jenkins会杀死在构建过程中产生的作业,如果您希望将此过程保留为守护进程,那就是个问题.

Also note that running npm start from a Jenkins job will spawn a new process and Jenkins will kill the jobs spawned during a build, That is a problem if you want this process to remain as a daemon.

为避免出现这种情况,您需要在命令前提供一个标志:

To avoid that you need to to provide a flag right before your command:

BUILD_ID=dontKillMe npm start &

您尚未具体说明工作流程中的所有步骤,但我想您会在尝试构建第一个作业后尝试执行一些后构建操作,因此发现您的进程未运行会导致后续操作失败工作.

You haven't been specific about all the steps in your job pipeline but I imagine that you try to perform some post-build operation after your first job's build so finding out that your process is not running causing will cause failure in subsequent jobs.

也请尝试使用永远.它将确保脚本一直运行直到停止为止,并可以像这样启动应用程序:

Also, try using forever. It will ensure that your script is running continuously until you stop it, with it you can start your application like this:

BUILD_ID=dontKillMe forever start yourApp.js

这篇关于node.js服务器未在詹金斯中给出成功状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:20