Richlewis
Richlewis

Reputation: 15384

How to trigger another Jenkins build if current not finished

I have a Jenkins build that for the first part will launch a webserver on localhost, the build gets to a point where the application is served:

Running "connect:server_jenkins" (connect) task
Waiting forever...
Started connect web server on http://localhost:3000

My problem here is that after this I can't do anything else can I, no other shell commands will run until this process has an exit code I believe. I would even happily trigger another build at this point.

The purpose of this is that the application gets setup and then I have functional tests (Cucumber) that run.

How can I approach this?

Upvotes: 1

Views: 649

Answers (1)

Gerold Broser
Gerold Broser

Reputation: 14782

Spawning a new process asynchronously depends on your OS/Shell:

Windows

MS TechNet, Command-Line Reference, Start:

Starts a separate Command Prompt window to run a specified program or command.

Bash

Bash Reference Manual, 3.2.5 Coprocesses:

A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the '&' control operator, ...

See also How do you use the command coproc in Bash? with its great accepted answer.

To prevent Jenkins to kill all processes on job finish see Use Jenkins > ProcessTreeKiller:

To reliably kill processes spawned by a job during a build, Jenkins contains a bit of native code to list up such processes and kill them.

...

If your build wants to leave a daemon running behind...

... change the environment variable BUILD_ID which Jenkins's ProcessTreeKiller is looking for. This will cause Jenkins to assume that your daemon is not spawned by the Jenkins build.

BUILD_ID=dontKillMe

I tried the following in a Build step → Execute Windows batch commandCommand:

start ..\..\jobs\<job's name>\endless.cmd

(Relative path depending on Manage JenkinsConfigure SystemAdvanced...Workspace Root Directory, I use ${JENKINS_HOME}/workspace/${ITEM_FULLNAME})

with endless.cmd containing:

set BUILD_ID=dontKillMe

ping -t localhost

and it worked:

  • the build finished successfully
  • two processes, cmd.exe and ping.exe, keep running

Since your build continues immediately after spawning the asynchronous process you most probably have to wait for a certain time, or check for a file existing etc., before you really continue.

Upvotes: 1

Related Questions