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

[JENKINS-62220] Automatically select owner for GitHubAppCredentials acc. to context #527

Merged
merged 8 commits into from May 6, 2022

Conversation

jglick
Copy link
Member

@jglick jglick commented Mar 23, 2022

https://issues.jenkins.io/browse/JENKINS-62220

Uses jenkinsci/credentials-plugin#293 to ensure that the owner field may be left blank yet the appropriate org will still be selected for a particular build. (At least assuming the lookup is via CredentialsProvider.findCredentialById, which passes a Run, as it would be for example in a withCredentials block.)

See discussions e.g. at #290 (comment) or #269 (comment).

Tested with jenkinsci/git-plugin#1242 and an App installed on my account as well as a test org. Was able to create a multibranch project on a private repo in my account

node {
  checkout scm
  withCredentials([usernamePassword(credentialsId: '', passwordVariable: 'GITHUB_TOKEN', usernameVariable: 'xxx')]) {
    sh 'gh repo view'
  }
}

and run builds and get commit statuses.

When creating the App credentials, if you want to use the Test Connection button, you need to temporarily enter an Owner since otherwise there is no context, but you do not need to save it. When selecting the credentials in a dropdown on a branch source, the automatic connection check (which shows the remaining rate limit) will work so long as you have typed in an owner (org folder) or repo URL (multibranch folder).

@jglick jglick changed the title [JENKINS-62220] Automatically select owner for GitHubAppCredentials acc. to requesting Run [JENKINS-62220] Automatically select owner for GitHubAppCredentials acc. to context Mar 23, 2022
@jglick jglick requested a review from timja March 23, 2022 20:27
@jglick jglick requested a review from nrayapati March 23, 2022 20:27
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

nice, long standing issue where you had to duplicate this

}

@NonNull
@Override
Copy link
Member Author

Choose a reason for hiding this comment

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

Or could comment this out while reverting POM changes.

MarkEWaite added a commit to MarkEWaite/docker-lfs that referenced this pull request Mar 26, 2022
Includes GitHub App authentication enhancement from Jesse Glick for
credentials by context.

jenkinsci/github-branch-source-plugin#527
needs this so that it can use the enhancement in
jenkinsci/credentials-plugin#293

Otherwise `withCredentials` works but `checkout scm` does not work
MarkEWaite added a commit to MarkEWaite/docker-lfs that referenced this pull request Mar 26, 2022
jenkinsci/github-branch-source-plugin#527 is a
draft pull request to automatically select owner for
GitHubAppCredentials acc. to context.

https://issues.jenkins.io/browse/JENKINS-62220 asks to allow GitHub
Apps to support credentials with multiple organizations
@LeoQuote
Copy link

LeoQuote commented Apr 4, 2023

hate to bother you like this, but I encoutered https://issues.jenkins.io/browse/JENKINS-70984 this issue recently, I tried to fix other issue by two pr above, but this one is really hard for me, could you please help me with that, the reason seems to be that the git client is not passing context when getting credential.

 Found multiple installations for GitHub app ID 9 but none match credential owner "null". Set the right owner in the credential advanced options

could you please hint me or give me some document to read so I can figure it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants