A stage requires a long-running process (a test server) that must be stopped even if tests fail.
IntermediateScenarioJenkins Pipelines and Agents
Answer
Situation read → Background process lifecycle inside a stage.
What I'd do →
- Start with
sh 'nohup ./start-server.sh > server.log 2>&1 & echo $! > server.pid', wait for the port, run tests. - Stop in
post { always { sh 'kill $(cat server.pid) || true' } }. - Better: run the server as a container started in
docker.image(...).withRun { c -> ... }, which cleans up automatically.
Why → withRun ties resource lifetime to the block even on failure.
Interview tip → Note Jenkins' BUILD_ID process killer: set JENKINS_NODE_COOKIE=dontKillMe only when a process must outlive the build.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner