How to start background process from a TeamCity build step
Completed
When I try to start a background process from my Custom Script Step Runner in TeamCity, I see that it terminates the background process as soon as the step completes. Is there a way to keep the background process running?
Here's what I am trying to do in my step:
ORACLE_POD_NAME=`...complex logic here...`
oc port-forward $ORACLE_POD_NAME 15210:1521 &
PORT_FORWARD_PID=$!
echo $PORT_FORWARD_PID > port_forward.pid
The idea is to create a persistent port forward to my OpenShift pod for the duration of the build, b/c many subsequent build steps will need it. I would then kill the port forward process using the PID I wrote into the file.
Unfortunately 'oc port-forward' is already terminated by the time I get to the next step. Is there a way to get this to work?
Please sign in to leave a comment.
The solution was to disconnect the inputs and outputs of the background subprocess I am launching from the parent process, and tell the subprocess not to respond to
HUP (hangup)signal.This ensures that the port-forward process survives TeamCity step termination, thus making port-forwarding available to subsequent build steps.