feat: expose the credential username via an optional usernameVariable - #285
Merged
ogulcanaydogan merged 1 commit intoJul 20, 2026
Merged
Conversation
The sshagent step only exposed SSH_AUTH_SOCK and SSH_AGENT_PID, so there was no way to pass the credential's SSH user to ssh -l without hardcoding it. Add an optional usernameVariable parameter that binds the first resolved credential's username to the given environment variable inside the block, mirroring the withCredentials usernameVariable convention. It survives agent resume and is unset by default, so existing pipelines are unaffected. Closes jenkinsci#234 Signed-off-by: Ogulcan Aydogan <[email protected]>
ogulcanaydogan
force-pushed
the
feature/username-variable
branch
from
July 20, 2026 08:32
63627a6 to
d28da61
Compare
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
sshagentstep only exposedSSH_AUTH_SOCKandSSH_AGENT_PID, so there was no way to pass the credential's SSH user tossh -lwithout hardcoding it (JENKINS-45312).This adds an optional
usernameVariableparameter that binds the first resolved credential's username to that environment variable inside the block:It mirrors the
withCredentialsusernameVariableconvention, survives agent resume (it is stored on the step execution rather than the transient step), and is unset by default so existing pipelines are unaffected. With multiple credentials it uses the first.Testing
Added
exposesCredentialUsernameViaUsernameVariabletoSSHAgentStepWorkflowTest, which runssshagent(..., usernameVariable: 'SSH_USER')and asserts$SSH_USERresolves to the credential's username.mvn test -Dtest=SSHAgentStepWorkflowTest#exposesCredentialUsernameViaUsernameVariablepasses.Closes #234