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 primary field to REST API #445

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

MarkRx
Copy link
Contributor

@MarkRx MarkRx commented Apr 3, 2024

Exposes a "primary" field to the REST API indicating if the SCM declared the branch as a default/primary branch.

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

Requires jenkinsci/scm-api-plugin#259 to see PrimaryInstanceMetadataAction class.

Testing done

Create a multi-branch pipeline branch with "myprinarybranch" as the default branch

Primary Branch

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

<workflowJob _class="org.jenkinsci.plugins.workflow.job.WorkflowJob">
    <property _class="org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty">
        <branch>
            <action _class="jenkins.scm.api.metadata.PrimaryInstanceMetadataAction"/>
            <head _class="jenkins.plugins.git.GitBranchSCMHead">
                <name>myprimarybranch</name>
                <origin _class="jenkins.scm.api.SCMHeadOrigin$Default"/>
            </head>
            <scm _class="hudson.plugins.git.GitSCM">
                <type>hudson.plugins.git.GitSCM</type>
                <branche/>
                <mergeOptions/>
                <userRemoteConfig/>
            </scm>
        </branch>
    </property>
</workflowJob>
{
    "_class": "org.jenkinsci.plugins.workflow.job.WorkflowJob",
    "property": [
        {
            "_class": "org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty",
            "branch": {
                "actions": [
                    {
                        "_class": "jenkins.scm.api.metadata.PrimaryInstanceMetadataAction"
                    }
                ],
                "head": {
                    "_class": "jenkins.plugins.git.GitBranchSCMHead",
                    "name": "myprimarybranch",
                    "origin": {
                        "_class": "jenkins.scm.api.SCMHeadOrigin$Default"
                    }
                },
                "properties": [],
                "scm": {
                    "_class": "hudson.plugins.git.GitSCM",
                    "browser": null,
                    "type": "hudson.plugins.git.GitSCM",
                    "branches": [
                        {}
                    ],
                    "mergeOptions": {},
                    "userRemoteConfigs": [
                        {}
                    ]
                }
            }
        }
    ]
}

Non-Primary Branch

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

<workflowJob _class="org.jenkinsci.plugins.workflow.job.WorkflowJob">
    <property _class="org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty">
        <branch>
            <head _class="jenkins.plugins.git.GitBranchSCMHead">
                <name>otherbranch</name>
                <origin _class="jenkins.scm.api.SCMHeadOrigin$Default"/>
            </head>
            <scm _class="hudson.plugins.git.GitSCM">
                <type>hudson.plugins.git.GitSCM</type>
                <branche/>
                <mergeOptions/>
                <userRemoteConfig/>
            </scm>
        </branch>
    </property>
</workflowJob>
{
    "_class": "org.jenkinsci.plugins.workflow.job.WorkflowJob",
    "property": [
        {
            "_class": "org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty",
            "branch": {
                "actions": [],
                "head": {
                    "_class": "jenkins.plugins.git.GitBranchSCMHead",
                    "name": "otherbranch",
                    "origin": {
                        "_class": "jenkins.scm.api.SCMHeadOrigin$Default"
                    }
                },
                "properties": [],
                "scm": {
                    "_class": "hudson.plugins.git.GitSCM",
                    "browser": null,
                    "type": "hudson.plugins.git.GitSCM",
                    "branches": [
                        {}
                    ],
                    "mergeOptions": {},
                    "userRemoteConfigs": [
                        {}
                    ]
                }
            }
        }
    ]
}

Submitter checklist

Preview Give feedback

@MarkRx MarkRx requested a review from a team as a code owner April 3, 2024 15:55
@jglick
Copy link
Member

jglick commented Apr 12, 2024

this could also alternatively be achieved by exporting the Branch actions to the API

That feels like the more general way to do this, at the expense of a slightly more complicated URL. Would mean adding @ExportedBean to at least PrimaryInstanceMetadataAction.

@MarkRx MarkRx force-pushed the feature/JENKINS-72958 branch from bc79131 to 9b251ab Compare April 22, 2024 16:54
@MarkRx
Copy link
Contributor Author

MarkRx commented Apr 22, 2024

Updated to expose beans instead.

jenkinsci/scm-api-plugin#259 for scm-api change

This will function without the above change but it won't show PrimaryInstanceMetadataAction. This means it can be merged independent of the scm-api changes though it would also be an option to wait for the scm-api release then bump up the dependency version to ensure the exposing of PrimaryInstanceMetadataAction is pulled in.

@rsandell rsandell changed the title JENKINS-72958 expose primary field to REST API [JENKINS-72958] expose primary field to REST API Apr 23, 2024
@rsandell rsandell merged commit af1064e into jenkinsci:master Apr 23, 2024
14 checks passed
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