-
Notifications
You must be signed in to change notification settings - Fork 165
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-50122 Authorization should work with basic Workflow jobs #99
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,11 @@ private String getRepositoryName() { | |
Describable scm = null; | ||
if (this.item instanceof WorkflowJob) { | ||
WorkflowJob project = (WorkflowJob) item; | ||
scm = project.getProperty(BranchJobProperty.class).getBranch().getScm(); | ||
if (project.getProperty(BranchJobProperty.class) != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the wrong API. Do not depend on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jglick sorry I'm confused. If I understand correctly, you're suggesting to get the And thus we could just do something like this: if (this.item instanceof SCMSourceOwner) {
project = (SCMSourceOwner)this.item;
// probably check that there's at least one source here
scm = (SCMSource) project.getSCMSources().get(0);
} else if (this.item instanceof WorkflowJob) {
project = (WorkflowJob)this.item;
scm = project.getTypicalSCM();
} else if (this.item instanceof AbstractProject) {
AbstractProject project = (AbstractProject) item;
scm = project.getScm();
}
... Would that work and cover all kind of multi-branch projects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The multibranch folder ( If you are looking for an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jglick from what I understand of the plugin code (I'm not the original author) any type of So that means not only things that implements If I followed correctly, we could rewrite this code to be as simple as: if (this.item instanceof SCMSourceOwner) {
// covers multi-branch folders and multibranch workflow job
project = (SCMSourceOwner)this.item;
// need to check there's at least one
scm = (SCMSource) project.getSCMSources().get(0);
} else if (this.item instanceof SCMTriggerItem) {
// covers all projects that have an SCM (AbstractProject, WorkflowJob etc...)
project = (SCMTriggerItem)this.item;
// need to check there's at least one
scm = project. getSCMs().get(0);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
|
||
scm = project.getProperty(BranchJobProperty.class).getBranch().getScm(); | ||
} else { | ||
scm = project.getTypicalSCM(); | ||
} | ||
} else if (this.item instanceof MultiBranchProject) { | ||
MultiBranchProject project = (MultiBranchProject) item; | ||
scm = (SCMSource) project.getSCMSources().get(0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why check types at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about Jenkins internals to be able to answer that question (and I'm not the original author), it's just that restricting to jobs with
BranchJobProperty
is too restrictive.Is it possible that not all
Job
areAbstractProject
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice
Job
s areAbstractProject
—freestyle, matrix, Maven, the traditional typesWorkflowJob
Generally, you should not downcast without a good reason.