Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CredentialsProvider.findCredentialById whenever possible #1242

Merged
merged 3 commits into from
Mar 26, 2022

Conversation

jglick
Copy link
Member

@jglick jglick commented Mar 26, 2022

Required for jenkinsci/github-branch-source-plugin#527 to take advantage of jenkinsci/credentials-plugin#293. Otherwise withCredentials works but checkout scm does not.

@jglick jglick marked this pull request as draft March 26, 2022 00:29
@jglick jglick requested review from MarkEWaite and timja March 26, 2022 00:29
@jglick jglick marked this pull request as ready for review March 26, 2022 00:36
@MarkEWaite MarkEWaite added the enhancement Improvement or new feature label Mar 26, 2022
Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

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

Two questions that do not block the merge. The change looks good to me. I'm running this build along with the credentials plugin and the GitHub branch source plugin that match it. No issues detected. I haven't added an app credential to test the new path.

src/main/java/hudson/plugins/git/GitSCM.java Outdated Show resolved Hide resolved
src/main/java/hudson/plugins/git/GitSCM.java Outdated Show resolved Hide resolved
@jglick
Copy link
Member Author

jglick commented Mar 26, 2022

I added some more explanation of the API and its usage from this PR in jenkinsci/credentials-plugin#293.

@MarkEWaite
Copy link
Contributor

@jglick I think this is ready to merge and be released. Any reason that I should not merge it and release it so that it is available in a released version?

…nt` overloads.

This allows methods to be simplified by dropping the `Job` / `Item` parameter;
and allows us to drop the `CredentialsProvider.lookupCredentials` code branch,
so that `CredentialsProvider.findCredentialById` can be called whenever there are credentials.
@@ -829,13 +828,13 @@ private PollingResult compareRemoteRevisionWithImpl(Job<?, ?> project, Launcher
* @throws InterruptedException when interrupted
*/
@NonNull
public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,?> build, FilePath workspace) throws IOException, InterruptedException {
public GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run<?,?> build, FilePath workspace) throws IOException, InterruptedException {
Copy link
Member Author

Choose a reason for hiding this comment

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

I started off inspecting https://cs.github.com/?scope=org%3Ajenkinsci&scopeName=jenkinsci&q=GitSCM.createClient to be sure adding @NonNull here was safe, until I realized that we are dereferencing it just below anyway!

if (project != null && project.getLastBuild() != null) {
CredentialsProvider.track(project.getLastBuild(), credentials);
}
CredentialsProvider.track(build, credentials); // TODO unclear if findCredentialById was meant to do this in all cases
Copy link
Member Author

Choose a reason for hiding this comment

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

See comment in upstream PR. Seems to have been forgotten. Probably cleaner to have track be called upstream, but deferring that for now.

Comment on lines -949 to -951
project instanceof Queue.Task
? ((Queue.Task) project).getDefaultAuthentication()
: ACL.SYSTEM,
Copy link
Member Author

Choose a reason for hiding this comment

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

findCredentialById has a rather subtler sequence of logic which I do not entirely follow, but seems best to use the official version. (Apparently relevant to supporting credentials parameters, input step, etc.)

@jglick
Copy link
Member Author

jglick commented Mar 26, 2022

Any reason that I should not merge it and release it

If I thought there were, I would mark it as draft! But thanks for the tip about lastBuild, that allowed the patch to be cleaned up considerably.

@jglick jglick marked this pull request as draft March 26, 2022 14:22
@jglick jglick marked this pull request as ready for review March 26, 2022 14:24
@MarkEWaite
Copy link
Contributor

I've reviewed the most recent changes and they look very good to me. I'll merge, run some additional interactive testing, and then release it.

@MarkEWaite MarkEWaite merged commit fb3fcec into jenkinsci:master Mar 26, 2022
@jglick jglick deleted the Credentials.forRun branch March 26, 2022 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants