[JIRA] (JENKINS-52747) Jenkins REST API - Cannot determine source SCM when using multiple scms in Pipeline

5 views
Skip to first unread message

mrichar2@paychex.com (JIRA)

unread,
Jul 26, 2018, 4:11:03 PM7/26/18
to jenkinsc...@googlegroups.com
Mark R updated an issue
 
Jenkins / Improvement JENKINS-52747
Jenkins REST API - Cannot determine source SCM when using multiple scms in Pipeline
Change By: Mark R
Summary: Jenkins REST API - Cannot determine commit repo source SCM when using multiple scms in Pipeline
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

mrichar2@paychex.com (JIRA)

unread,
Jul 26, 2018, 4:11:03 PM7/26/18
to jenkinsc...@googlegroups.com
Mark R updated an issue
When a build has commits from multiple repositories (such as when using the multi-scm plugin or a pipeline job) it isn't possible to determine what repository (remote URL) a commit came from using the REST API.

The issue is neither a ChangeLogSet or a ChangeLogSet.Entry has any knowledge of the SCM it came from. Thus when the bean is exported the API does not have that information.

I believe the solution would be to add knowledge of the SCM (or even just remote URL) to the ChangeLogSet when the list of changeset(s) is built ([WorkflowRun|https://github.com/jenkinsci/workflow-job-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java#L971] for Jenkinsfiles and [AbstractBuild.getChangeSet()|https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/AbstractBuild.java#L817] for Freestyle jobs). This would cause the source SCM information to be exposed in the API.

For example, given a Jenkinsfile job with 4 git repos that only had commit changes for 2 of them the API response might look like the json below. Observe that it there is no way to know which remote a changeset came from. See the attached file for more details.

http://myjenkins:8080/view/folder/job/foo/job/master/17/api/json?pretty=true

{code:json}
"changeSets" : [
    {
      "_class" : "hudson.plugins.git.GitChangeSetList",
      "items" : [
        {
          "_class" : "hudson.plugins.git.GitChangeSet",
          "affectedPaths" : [
            ...
          ],
          "commitId" : "4da434ef7fccefa9a0922ee49556319efc923973",
          ...
        },
        {
          "_class" : "hudson.plugins.git.GitChangeSet",
          "affectedPaths" : [
            ...
          ],
          "commitId" : "b23c08d558786dd73ef5ba20737c485a6406a9f4",
          ...
        }
      ],
      "kind" : "git"
    },
    {
      "_class" : "hudson.plugins.git.GitChangeSetList",
      "items" : [
        {
          "_class" : "hudson.plugins.git.GitChangeSet",
          "affectedPaths" : [
            ...
          ],
          "commitId" : "86593c915bf11f17d477072895a5afd2e5cb733f",
          ...
        }
      ],
      "kind" : "git"
    }
  ],
{code}

mrichar2@paychex.com (JIRA)

unread,
Jul 26, 2018, 4:12:01 PM7/26/18
to jenkinsc...@googlegroups.com
Mark R updated an issue
When a build has commits from multiple repositories (such as when using a pipeline job) it isn't possible to determine what repository (remote URL) a commit came from using the REST API.


The issue is neither a ChangeLogSet or a ChangeLogSet.Entry has any knowledge of the SCM it came from. Thus when the bean is exported the API does not have that information.

I believe the solution would be to add knowledge of the SCM (or even just remote URL) to the ChangeLogSet when the list of changeset(s) is built ([WorkflowRun .getChangeSets() |https://github.com/jenkinsci/workflow-job-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java#L971] for Jenkinsfiles and [AbstractBuild.getChangeSet()|https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/AbstractBuild.java#L817] for Freestyle jobs). This would cause the source SCM information to be exposed in the API.

mrichar2@paychex.com (JIRA)

unread,
Jul 26, 2018, 4:12:02 PM7/26/18
to jenkinsc...@googlegroups.com
Mark R edited a comment on Improvement JENKINS-52747
 
Re: Jenkins REST API - Cannot determine source SCM when using multiple scms in Pipeline
When the list of changeset(s) is built ([WorkflowRun .getChangeSets() |https://github.com/jenkinsci/workflow-job-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java#L971] for Jenkinsfiles and [AbstractBuild.getChangeSet()|https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/AbstractBuild.java#L817] for Freestyle jobs) all that would be needed is to attach information about the SCM to each ChangeLogSet that is returned.

mrichar2@paychex.com (JIRA)

unread,
Jul 26, 2018, 4:14:01 PM7/26/18
to jenkinsc...@googlegroups.com
Mark R updated an issue
Change By: Mark R
When a build has commits from multiple repositories (such as when using a pipeline job) it isn't possible to determine what repository (remote URL) a commit came from using the REST API.

The issue is neither a ChangeLogSet or a ChangeLogSet.Entry has any knowledge of the SCM it came from. Thus when the bean is exported the API does not have that information.

If there are multiple repositories in play it becomes impossible to know the repository a commit came from.

I believe the solution would be to add knowledge of the SCM (or even just remote URL) to the ChangeLogSet when the list of changeset(s) is built ([WorkflowRun.getChangeSets()|https://github.com/jenkinsci/workflow-job-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java#L971] for Jenkinsfiles and [AbstractBuild.getChangeSet()|https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/AbstractBuild.java#L817] for Freestyle jobs). This would cause allow a consumer of the source SCM information to be exposed in the API to know which SCMs a commit came from .

dbeck@cloudbees.com (JIRA)

unread,
Jul 27, 2018, 11:35:02 AM7/27/18
to jenkinsc...@googlegroups.com
Daniel Beck commented on Improvement JENKINS-52747
 
Re: Jenkins REST API - Cannot determine source SCM when using multiple scms in Pipeline

Notably, AFAIUI, the same problem exists with one SCM, multiple repos, like e.g. Subversion supports, so the problem might well be more common than described here. When I wrote https://github.com/jenkinsci/tortoisesvn-browser-plugin I had to guess based on the revision in the changelog. All built-in repo browsers fail at this.

jay.hendren@colorado.edu (JIRA)

unread,
Jul 27, 2018, 11:58:02 AM7/27/18
to jenkinsc...@googlegroups.com

I think it's also worth mentioning that it's not only the REST API that has this shortcoming, but also the Java/Groovy API.

dbeck@cloudbees.com (JIRA)

unread,
Jul 27, 2018, 12:08:02 PM7/27/18
to jenkinsc...@googlegroups.com

Right, which is why SCM browsers have this problem in Subversion Plugin.

crossan007@gmail.com (JIRA)

unread,
Jun 28, 2019, 10:46:02 AM6/28/19
to jenkinsc...@googlegroups.com

I'm encountering this issue as well.   I just discovered this Jira ticket after posting on StackOverflow: https://devops.stackexchange.com/questions/3798/determine-the-url-for-a-scm-trigger-from-inside-the-build/8496#8496

 

Based on the description above, it would seem that all historic SCM `GitChangeSetList` instances in old jobs would be missing the upstream `repoUrl` even if this issue were to be resolved in a future version?  Or would there be some mechanism by which old `GitChangeSetList` instances could be linked with an SCM `browser`?

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)
Reply all
Reply to author
Forward
0 new messages