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-72958] expose buildable property on MultiBranchProject to API #468

Closed
wants to merge 2 commits into from

Conversation

MarkRx
Copy link
Contributor

@MarkRx MarkRx commented Jul 12, 2024

Exposes the "buildable" field to the REST API indicating if the multi-branch job has been disabled

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

Testing done

Create a multi-branch pipeline branch. Enable it. Disable it.

http://localhost:8080/jenkins/job/test/job/myprimarybranch/api/xml?tree=property[buildable[*]]

Enabled

<workflowMultiBranchProject _class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject">
    <buildable>true</buildable>
</workflowMultiBranchProject>
{
    _class: "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject",
    buildable: true
}

Disabled

<workflowMultiBranchProject _class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject">
    <buildable>false</buildable>
</workflowMultiBranchProject>
{
    _class: "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject",
    buildable: false
}

Submitter checklist

@MarkRx MarkRx requested a review from a team as a code owner July 12, 2024 16:20
@MarkRx
Copy link
Contributor Author

MarkRx commented Sep 16, 2024

@MarkRx
Copy link
Contributor Author

MarkRx commented Nov 13, 2024

@basil @jtnord @rsandell someone please review and merge thanks

@jtnord
Copy link
Member

jtnord commented Nov 14, 2024

I have a feeling this is a bug in Stapler and not this plugin.
The ExportedBean is called out as only needed to be present on the base class and that properties annotated with Exported would be exported.
As the Exported annotation is present on the root of the method definition where the property is defined (not the overriding method) I would expect this to be honored, but https://github.com/jenkinsci/stapler/blob/f3b7f8789e7977a1caec5ba0a293503f00cd89e1/core/src/main/java/org/kohsuke/stapler/export/Model.java#L73-L132 is possibly not doing this (or possibly the annotation processor).

@jtnord jtnord changed the title JENKINS-72958 expose buildable property on MultiBranchProject to API [JENKINS-72958] expose buildable property on MultiBranchProject to API Nov 14, 2024
@jtnord
Copy link
Member

jtnord commented Nov 14, 2024

I am also confused as to why

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
String displayName = getDisplayNameOrNull();
if (displayName == null) {
ObjectMetadataAction action = getAction(ObjectMetadataAction.class);
if (action != null && StringUtils.isNotBlank(action.getObjectDisplayName())) {
return action.getObjectDisplayName();
}
}
return super.getDisplayName();
}
shows up in the API which is not tagged as Exported but overridden...

@jtnord
Copy link
Member

jtnord commented Nov 14, 2024

I am also confused as to why

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
String displayName = getDisplayNameOrNull();
if (displayName == null) {
ObjectMetadataAction action = getAction(ObjectMetadataAction.class);
if (action != null && StringUtils.isNotBlank(action.getObjectDisplayName())) {
return action.getObjectDisplayName();
}
}
return super.getDisplayName();
}

shows up in the API which is not tagged as Exported but overridden...

Because this is an AbstractItem not a Job (by virtue of extending ComputedFolder) which is not Exported 🤦 AbstractItem does not define isBuildable but does have getDisplayName exported in its class hierachy.

Does it not make sense for all ComputedFolders to expose this rather than just MultiBranch projects?

jtnord added a commit to jenkinsci/cloudbees-folder-plugin that referenced this pull request Nov 14, 2024
@jtnord
Copy link
Member

jtnord commented Nov 14, 2024

@MarkRx jenkinsci/cloudbees-folder-plugin#441 if you would like to try that instead.

@MarkRx
Copy link
Contributor Author

MarkRx commented Nov 15, 2024

@jtnord tested works thanks!

http://localhost:8080/jenkins/job/folder1/job/pipeline1/api/json?tree=buildable

Enabled:

{
    _class: "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject",
    buildable: true
}

Disabled:

{
    _class: "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject",
    buildable: false
}

Note child jobs will have buildable=true even if the parent is disabled (buildable=false). The buildable property doesn't propagate so the parent job needs to be checked. This is existing behavior and unrelated to exposing the buildable property.

@jtnord
Copy link
Member

jtnord commented Nov 16, 2024

Closed as jenkinsci/cloudbees-folder-plugin#441 merged instead

@jtnord jtnord closed this Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants