Skip to content

fix: make ssh-agent teardown best-effort - #284

Merged
ogulcanaydogan merged 1 commit into
jenkinsci:masterfrom
ogulcanaydogan:fix/best-effort-teardown
Jul 20, 2026
Merged

fix: make ssh-agent teardown best-effort#284
ogulcanaydogan merged 1 commit into
jenkinsci:masterfrom
ogulcanaydogan:fix/best-effort-teardown

Conversation

@ogulcanaydogan

Copy link
Copy Markdown
Contributor

Stopping the agent runs ssh-agent -k during teardown. If the agent process was already gone (for example killed during a long build), the non-zero exit threw an AbortException that failed an otherwise successful build (JENKINS-43716).

This logs the failure instead of throwing, so teardown is best-effort. The message still includes the exit code and stderr, so a genuine problem is still visible in the build log.

Testing

Added teardownDoesNotFailBuildWhenAgentAlreadyStopped to SSHAgentStepWorkflowTest: it stops the agent from inside the sshagent block, so the automatic teardown finds it already gone, and asserts the build still succeeds and the failure is logged. Without the change the build fails on teardown. mvn test -Dtest=SSHAgentStepWorkflowTest#teardownDoesNotFailBuildWhenAgentAlreadyStopped,ExecRemoteAgentFailureMessageTest passes.

Fixes #230

Stopping the agent runs ssh-agent -k during teardown. If the agent process was
already gone, for example killed during a long build, the non-zero exit threw an
AbortException that failed an otherwise successful build.

Log the failure instead of throwing so cleanup is best-effort, and add a test
that stops the agent from inside the sshagent block and asserts the build still
succeeds.

Fixes jenkinsci#230

Signed-off-by: Ogulcan Aydogan <[email protected]>
@ogulcanaydogan
ogulcanaydogan requested a review from a team as a code owner July 17, 2026 13:59
@ogulcanaydogan
ogulcanaydogan merged commit 101ccbe into jenkinsci:master Jul 20, 2026
18 checks passed
+ "}\n", true)
);
WorkflowRun run = story.j.assertBuildStatusSuccess(job.scheduleBuild2(0));
story.j.assertLogContains("Failed to run ssh-agent -k", run);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogulcanaydogan could you disable this test please, unless there is some straightforward way to detect the sort of environment in which it can pass?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-43716] Job fails because the ssh agent cannot be killed

2 participants