Skip to content

[JENKINS-50777] Expose SCMRevisionAction and associated metadata via Stapler export#52

Merged
stephenc merged 1 commit into
jenkinsci:masterfrom
jglick:export-JENKINS-50777
Apr 17, 2018
Merged

[JENKINS-50777] Expose SCMRevisionAction and associated metadata via Stapler export#52
stephenc merged 1 commit into
jenkinsci:masterfrom
jglick:export-JENKINS-50777

Conversation

@jglick

@jglick jglick commented Apr 12, 2018

Copy link
Copy Markdown
Member

JENKINS-50777

Example output with jenkinsci/git-plugin#581 + jenkinsci/github-branch-source-plugin#180 on a master build:

{
  "_class" : "jenkins.scm.api.SCMRevisionAction",
  "revision" : {
    "_class" : "jenkins.plugins.git.AbstractGitSCMSource$SCMRevisionImpl",
    "deterministic" : true,
    "head" : {
      "_class" : "org.jenkinsci.plugins.github_branch_source.BranchSCMHead",
      "name" : "master",
      "origin" : {
        "_class" : "jenkins.scm.api.SCMHeadOrigin$Default"
      }
    },
    "hash" : "c9e8148ede406f8ad89610befbdf51ba4a0ef24a"
  }
}

and on a PR merge build, specifically cloudbeers/PR-demo#20:

{
  "_class" : "jenkins.scm.api.SCMRevisionAction",
  "revision" : {
    "_class" : "org.jenkinsci.plugins.github_branch_source.PullRequestSCMRevision",
    "deterministic" : true,
    "head" : {
      "_class" : "org.jenkinsci.plugins.github_branch_source.PullRequestSCMHead",
      "name" : "PR-20",
      "origin" : {
        "_class" : "jenkins.scm.api.SCMHeadOrigin$Fork",
        "name" : "vivek"
      }
    },
    "merge" : true,
    "target" : {
      "_class" : "jenkins.plugins.git.AbstractGitSCMSource$SCMRevisionImpl",
      "deterministic" : true,
      "head" : {
        "_class" : "org.jenkinsci.plugins.github_branch_source.BranchSCMHead",
        "name" : "master",
        "origin" : {
          "_class" : "jenkins.scm.api.SCMHeadOrigin$Default"
        }
      },
      "hash" : "c9e8148ede406f8ad89610befbdf51ba4a0ef24a"
    },
    "pullHash" : "5d2f682bc7a77f253e9b887536fa08f7ba41af64"
  }
}

Example of extracting important fields from a build URL:

…/job/…/…/api/json?tree=actions[revision[hash,pullHash]]

*
* @since 2.2.0
*/
@ExportedBean

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that #35 exported SCMHead.origin yet neglected to add this annotation, causing

org.kohsuke.stapler.export.NotExportableException: class jenkins.scm.api.SCMHeadOrigin$Fork doesn't have @ExportedBean

@svanoort svanoort left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems okay to me...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants