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

SCMSource: Check task authentication context when looking forcredentials #30

Merged
merged 3 commits into from
Oct 27, 2021

Conversation

cghislai
Copy link
Contributor

GiteaSCMSource was sometimes using the authenticated user associated with the request.
This was causing occasional requests to be sent without authorization headers, and receiving 404 responses.
This could happen by manually triggering a single branch in a multi-branch pipeline project, or replaying a job. Triggering a job that lanches a parametrized build of a branch job also triggered the issue.

This change checks for Queue.Task instance, and fallbacks to the the System credential. This is what is done elsewhere.
The user associated with the request is this not used anymore when retrieving credentials by id.

Fixes JENKINS-62326

@justusbunsi
Copy link
Member

justusbunsi commented Sep 23, 2021

Hi. I think I am running into this issue often. So I'm happy to test drive your changes. Unfortunately, this is going to be a long running thing since it's not always happen.

@cghislai
Copy link
Contributor Author

cghislai commented Sep 23, 2021

@justusbunsi thanks. Remember you can compile the hpi and upload it to any running instance manually via the plugins page, thats how i tested it. (edit: didnt read the last few words. you should be able to trigger it by launching a multibranch pipeline job for one branch manually?)

@justusbunsi
Copy link
Member

justusbunsi commented Sep 23, 2021

you should be able to trigger it by launching a multibranch pipeline job for one branch manually

Hrm. Looks like I misinterpreted a lot. 🤦
After reviewing the stacktrace in the referenced issue, it don't look similar. 😕 I always get an error on fetching collaborators. Also, I am currently running my jobs as SYSTEM (bad idea), so I'm not affected by this issue.

java.lang.NullPointerException
	at org.jenkinsci.plugin.gitea.client.impl.DefaultGiteaConnection.fetchCollaborators(DefaultGiteaConnection.java:391)
	at org.jenkinsci.plugin.gitea.GiteaSCMSource.getTrustedRevision(GiteaSCMSource.java:603)
	at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:104)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:309)
	at hudson.model.ResourceController.execute(ResourceController.java:100)
	at hudson.model.Executor.run(Executor.java:433)

Anyway, I'll test your changes. Reading the issue and your suggestion on reproducing the issue, it happens all the time, right?

@cghislai
Copy link
Contributor Author

Yes that is a different issue, please file a bug report if none exists already. I was able to trigger the issue at hand here by running a branch job on a multibranch project using gitea scm, every time indeed.

@justusbunsi
Copy link
Member

@cghislai Please sync with master branch to get a working build.

@lafriks lafriks added the bug label Oct 27, 2021
@lafriks lafriks added this to the 1.3.0 milestone Oct 27, 2021
@lafriks lafriks merged commit 8214d21 into jenkinsci:master Oct 27, 2021
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.

3 participants