[JIRA] [multi-branch-project-plugin] (JENKINS-34698) Allow picking a Browser for Git

2 views
Skip to first unread message

nolange79@gmail.com (JIRA)

unread,
May 9, 2016, 6:15:01 PM5/9/16
to jenkinsc...@googlegroups.com
Norbert Lange created an issue
 
Jenkins / Improvement JENKINS-34698
Allow picking a Browser for Git
Issue Type: Improvement Improvement
Assignee: Matthew DeTullio
Components: multi-branch-project-plugin
Created: 2016/May/09 10:14 PM
Priority: Minor Minor
Reporter: Norbert Lange

Hello,

Currently there is no way to specify a Browser for linking to the commit/files/diffs for changes.
Either there should be a way to specify the Browser in the Piepeline configuration, or there should be a way to - for example - add the browser to the scm variable.

A third option would be to allow configuring a global mapping between the "host:port" of a connection to a browser. I coded such a scheme and it works for normal Pipelines, but it doesnt for Multibranch Pipeline.
With this one could set a mapping from the clone-urls to the projects web-url and additional stuff like browser information

@NonCPS
def call(name) {
    def servermap = [
        'localhost:10022': [browser: [$class: 'GogsGit', repoUrl: 'http://localhost:10080'],
            credentialsId: 'aad288c5-ea8e-4484-8e2d-9dc7abab7910', ],
        ]
    def repomap = [
        'tools': [git: 'ssh://git@localhost:10022/mn/tools.git', ],
        'firmware': [git: 'ssh://git@localhost:10022/mn/firmware.git', ],
        'jenkins-jobscripts': [git: 'ssh://git@localhost:10022/mn/jenkinspipeline.git', ],
    ]
    
    def repo = repomap[name]
    
    if (repo != null) {
        repo = repo.clone()
        def url = repo['git']
        if (url != null) {
            url = url - '.git'
            def m = (url =~ '.*://(.*@)?([^#/]*)/([^#]*)')
            def repohost = m[0][2].trim()
            def vcsurl = m[0][3].trim()
            def serverinfo = servermap[repohost]
            if (serverinfo != null) {
                if (serverinfo.browser?.repoUrl != null) {
                    // take the path component of the clone url, and apeend to the 
                    // base webpage-url from the server
                    def browser = [:] + serverinfo.browser
                    browser['repoUrl'] = browser['repoUrl'] + '/' + vcsurl
                    serverinfo = [:] + serverinfo
                    serverinfo['browser'] = browser
                }
                repo.putAll(serverinfo)
            }
        }
    }
    
    return repo
}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.2#64017-sha1:e244265)
Atlassian logo

chris@orr.me.uk (JIRA)

unread,
May 12, 2016, 5:27:01 AM5/12/16
to jenkinsc...@googlegroups.com
Christopher Orr updated an issue
Change By: Christopher Orr
Component/s: workflow-multibranch-plugin
Component/s: multi-branch-project-plugin

chris@orr.me.uk (JIRA)

unread,
May 12, 2016, 5:27:02 AM5/12/16
to jenkinsc...@googlegroups.com
Change By: Christopher Orr
Assignee: Matthew DeTullio Manuel Jesús Recena Soto

recena@gmail.com (JIRA)

unread,
May 12, 2016, 5:35:01 AM5/12/16
to jenkinsc...@googlegroups.com
Manuel Jesús Recena Soto assigned an issue to Jesse Glick
Change By: Manuel Jesús Recena Soto
Assignee: Manuel Jesús Recena Soto Jesse Glick

jglick@cloudbees.com (JIRA)

unread,
May 12, 2016, 11:50:01 AM5/12/16
to jenkinsc...@googlegroups.com
Jesse Glick assigned an issue to Mark Waite
 

GitSCM.guessBrowser already supports GitHub. It could be expanded to cover other cases, but there would still be cases where the browser is unguessable, mainly for locally hosted browsers (as opposed to public services).

AbstractGitSCMSource could have a GitRepositoryBrowser field which it would pass on to GitSCM in build.

Change By: Jesse Glick
Component/s: git-plugin
Component/s: workflow-multibranch-plugin
Labels: multibranch workflow
Assignee: Jesse Glick Mark Waite

nolange79@gmail.com (JIRA)

unread,
May 12, 2016, 12:51:02 PM5/12/16
to jenkinsc...@googlegroups.com
Norbert Lange commented on Improvement JENKINS-34698
 
Re: Allow picking a Browser for Git

Dunno about the implementation cost, but this sound like a rather in-transparent scheme, and not really reflecting the usage. Typically you want to configure a server (and update/change) independent of the jobs using it

Wouldn`t it be easiest to add a section in the Jenkins preferences, mapping clone url prefixes to properties than solving the issue on multiple endpoints?
Eg. a configuration would look like:
'github.com' = [browser: [$class: 'GitHub', repoUrl: 'http://github.com']
'localhost:10022' = [browser: [$class: 'GogsGit', repoUrl: 'http://localhost:10080', credentialsId = 'blah' ]
'10.99.10.4' = [browser: [$class: 'Gitlab', repoUrl: 'http://10.99.10.4:8080/gitlab, version: '8.7'', credentialsId = 'blah2' ]

That would make migrations and upgrades of local servers very easy, while the predefined stuff like Github would be visible (and edible, like adding credentials?) to the user and not some magic in the plugin. Maybe you could even use a second table, to map names to servers or repositories, that way jobs are completely ignorant of the source repository - quite similar to how users only deal with "origin" in most local git repositories

mark.earl.waite@gmail.com (JIRA)

unread,
May 13, 2016, 8:04:02 AM5/13/16
to jenkinsc...@googlegroups.com

Norbert Lange, I think the global configuration of the git plugin could be extended to allow the administrator to define a mapping between the URL's used to clone a repository and the URL's used to browse a repository. Some of the examples from my test environment might include:

If the clone URL matches this then use this URL to browse the repository
git://mark-pc1.markwaite.net/git/(.*) http://mark-pc1.markwaite.net/gitweb/?p=\1
git://github.com/(.*)\.git https://github.com/\1
mwa...@mark-pc1.markwaite.net:/var/lib/git/(.*) http://mark-pc1.markwaite.net/gitweb/?p=\1

That mapping exercise seems complicated and error prone. I guess a "test button" would need to be added to the user interface as well so that the user could confirm that their mapping works.

mark.earl.waite@gmail.com (JIRA)

unread,
May 13, 2016, 8:06:02 AM5/13/16
to jenkinsc...@googlegroups.com
Mark Waite edited a comment on Improvement JENKINS-34698
[~nolange79], I think the global configuration of the git plugin could be extended to allow the administrator to define a mapping between the URL's used to clone a repository and the URL's used to browse a repository.  Some of the examples from my test environment might include:


|| If the clone URL matches this                                                || then use this URL to browse the repository ||
| git://mark-pc1.markwaite.net/git/(.*)                                        | http://mark-pc1.markwaite.net/gitweb/?p=\1 |
| git://github.com/(.*)\.git                                                            | https://github.com/\1                                     |
| mwa...@mark-pc1.markwaite.net:/var/lib/git/(.*)                    | http://mark-pc1.markwaite.net/gitweb/?p=\1 |

That mapping exercise seems complicated and error prone.  I guess a "test button" would need to be added to the user interface as well so that the user could  confirm that their mapping works.


It seems like the table of mappings could be quite complex, considering the different variations that are possible to convert between cloned URL and web browser URL.

mark.earl.waite@gmail.com (JIRA)

unread,
May 13, 2016, 8:07:01 AM5/13/16
to jenkinsc...@googlegroups.com
Mark Waite assigned an issue to Unassigned
 
Change By: Mark Waite
Assignee: Mark Waite

vvitkov@gmail.com (JIRA)

unread,
May 13, 2016, 10:09:04 AM5/13/16
to jenkinsc...@googlegroups.com
Vladimir Vitkov commented on Improvement JENKINS-34698
 
Re: Allow picking a Browser for Git

I would really like to see support for parameters defined in a parametrized builds.

E.g. we have a job that is manually triggered and can operate on several different repos (totally unrelated). At the moment the browser is not usable as we need to provide a parameter in the URL.

vvitkov@gmail.com (JIRA)

unread,
May 13, 2016, 10:12:01 AM5/13/16
to jenkinsc...@googlegroups.com
Vladimir Vitkov edited a comment on Improvement JENKINS-34698
I would really like to see support for parameters defined in a parametrized builds.

E.g. we have a job that is manually triggered and can operate on several different repos (totally unrelated). At the moment the browser is not usable as we need to provide a parameter in the URL.

vvitkov@gmail.com (JIRA)

unread,
May 13, 2016, 10:16:01 AM5/13/16
to jenkinsc...@googlegroups.com
Vladimir Vitkov edited a comment on Improvement JENKINS-34698
I would really like to see support for parameters defined in a parametrized builds.

E.g. we have a job that is manually triggered and can operate on several different repos (totally unrelated). At the moment the browser is not usable as we need to provide a parameter in the URL.

Sample
{code}Parameter: STAGE
GIT URI:  https  ssh ://stash.internal/ project prja /${STAGE}.git
Browser: https://stash.internal/project/
PRJA/ repos/${STAGE}{code}

mark.earl.waite@gmail.com (JIRA)

unread,
May 13, 2016, 10:21:01 AM5/13/16
to jenkinsc...@googlegroups.com

Vladimir Vitkov what you're proposing seems much more involved, and quite different from what is described in this enhancement request. Could you submit a separate enhancement request for that rather than risking that it will be missed inside this request?

It is more involved because the "changes" URL would need to be adapted based on the parameters of each job. I'm not sure the current interface between Jenkins core and the git plugin would support such a concept.

nolange79@gmail.com (JIRA)

unread,
May 13, 2016, 10:26:02 AM5/13/16
to jenkinsc...@googlegroups.com

I think the majority of the mappings could be catched with this transformation:

aproto://[auser@](ahost.xz[:aport]/[aprefix/])path/to/repo[.git] -> (bproto://bhost.xz[:bport]/[bprefix/][otherstuff])path/to/repo
ie. Take the substring from a clone URL, starting from hostname, ending before the repository path - name this clonebase from now on.
The rest of the clone URL is the repositorypath with a potentially trailing .git removed, together with the webbase you can form the repoUrl key for a specific "Git Browser" Instance.

Your idea of adding the target URL for a normal Browser, could be done in two ways: make the "Git Browser" Classes generate them from the repoUrl, or (taking Gitweb as example) add the query portion to the webbase and remove it when generating the repoUrl.

For the examples above, in a map that you can graphically configure in the global settings you`d have these entries:

clonebase webbase browser settings potential other stuff
mark-pc1.markwaite.net/git/ http://mark-pc1.markwaite.net/gitweb/?p= [$class: 'GitWeb']
github.com/ https://github.com/ [$class: 'GithubWeb']
mark-pc1.markwaite.net:/var/lib/git/ http://mark-pc1.markwaite.net/gitweb/?p= [$class: 'GitWeb']
localhost:10022/ http://localhost:10080/ [$class: 'GogsGit'] [userRemoteConfigs: [[credentialsId: 'aad288c5-ea8e-4484-8e2d-9dc7abab7910']]]
10.99.10.4/ http://10.99.10.4:8080/gitlab/ [$class: 'GitWeb' , version: '8.7']

ie. git://mark-pc1.markwaite.net/git/foo
-> finds clonebase = mark-pc1.markwaite.net/git/, repositorypath = foo, webbase = http://mark-pc1.markwaite.net/gitweb/?p=, browser = [$class: 'GitWeb']
-> website = webbase + repositorypath = http://mark-pc1.markwaite.net/gitweb/?p=foo
-> browserurl = http://mark-pc1.markwaite.net/gitweb-/?p=foo-
-> browser = [$class: 'GitWeb', repoUrl: 'http://mark-pc1.markwaite.net/gitweb']

I think a really big portions of the are covered with this rather simple scheme. Of yourse you can always have totally unrelated clone URS and webpages, and existing installations should still use the values specified in the jobs.
But it would be a nice way of having a configurable default.

  • the scp URLs [user@]host.xz:path/to/repo.git/ and raw file URLs /path/to/repo.git/ schould be internally converted to the "protocol URLS" for consistent clone URL syntax and simpler matching.
  • Matching a clonebase needs to take the longest match, so you could override a Server default for single repositories.

nolange79@gmail.com (JIRA)

unread,
May 13, 2016, 10:29:01 AM5/13/16
to jenkinsc...@googlegroups.com
Norbert Lange edited a comment on Improvement JENKINS-34698
I think the majority of the mappings could be catched with this transformation:

aproto://\[auser@](ahost.xz\[:aport]/\[aprefix/])path/to/repo[.git]  ->  (bproto://bhost.xz\[:bport]/\[bprefix/]\[otherstuff])path/to/repo
ie. Take the substring from a clone URL, starting from hostname, ending before the repository path - name this *clonebase* from now on.
The rest of the clone URL is the *repositorypath* with a potentially trailing .git removed, together with the *webbase* you can form the *repoUrl* key for a specific "Git Browser" Instance.

Your idea of adding the target URL for a normal Browser, could be done in two ways: make the "Git Browser" Classes generate them from the *repoUrl*, or (taking Gitweb as example) add the query portion to the *webbase* and remove it when generating the *repoUrl*.


For the examples above, in a map that you can graphically configure in the global settings you`d have these entries:
||clonebase||webbase||browser settings||potential other stuff||
|mark-pc1.markwaite.net/git/|http://mark-pc1.markwaite.net/gitweb/?p=|\[$class: 'GitWeb']|
|github.com/|https://github.com/|\[$class: 'GithubWeb']|
|mark-pc1.markwaite.net:/var/lib/git/|http://mark-pc1.markwaite.net/gitweb/?p=|\[$class: 'GitWeb']|
|localhost:10022/|http://localhost:10080/|\[$class: 'GogsGit']|\[userRemoteConfigs: \[\[credentialsId: 'aad288c5-ea8e-4484-8e2d-9dc7abab7910']]]|
|10.99.10.4/|http://10.99.10.4:8080/gitlab/|\[$class: ' GitWeb Gitlab ' , version: '8.7']|


ie. git://mark-pc1.markwaite.net/git/foo
-> finds clonebase = mark-pc1.markwaite.net/git/, repositorypath = foo, webbase = http://mark-pc1.markwaite.net/gitweb/?p=, browser = \[$class: 'GitWeb']
-> website = webbase + repositorypath = http://mark-pc1.markwaite.net/gitweb/?p=foo
-> browserurl = http://mark-pc1.markwaite.net/gitweb-/?p=foo-
-> browser = \[$class: 'GitWeb', repoUrl: 'http://mark-pc1.markwaite.net/gitweb']
-> add the browser and "other Stuff" fields to the checkout options (only those that arent explicitely set in a Job)

I think a really big portions of the are covered with this rather simple scheme. Of yourse you can always have totally unrelated clone URS and webpages, and existing installations should still use the values specified in the jobs.
But it would be a nice way of having a configurable default.

* the scp URLs [user@]host.xz:path/to/repo.git/ and raw file URLs /path/to/repo.git/ schould be internally converted to the "protocol URLS" for consistent clone URL syntax and simpler matching. 
* Matching a *clonebase* needs to take the longest match, so you could override a Server default for single repositories.

nolange79@gmail.com (JIRA)

unread,
May 13, 2016, 10:31:09 AM5/13/16
to jenkinsc...@googlegroups.com
Norbert Lange edited a comment on Improvement JENKINS-34698
I think the majority of the mappings could be catched with this transformation:

aproto://\[auser@](ahost.xz\[:aport]/\[aprefix/])path/to/repo[.git]  ->  (bproto://bhost.xz\[:bport]/\[bprefix/]\[otherstuff])path/to/repo
ie. Take the substring from a clone URL, starting from hostname, ending before the repository path - name this *clonebase* from now on.
The rest of the clone URL is the *repositorypath* with a potentially trailing .git removed, together with the *webbase* you can form the *repoUrl* key for a specific "Git Browser" Instance.

Your idea of adding the target URL for a normal Browser, could be done in two ways: make the "Git Browser" Classes generate them from the *repoUrl*, or (taking Gitweb as example) add the query portion to the *webbase* and remove it when generating the *repoUrl*.

For the examples above, in a map that you can graphically configure in the global settings you`d have these entries:
||clonebase||webbase||browser settings||potential other stuff||
|mark-pc1.markwaite.net/git/|http://mark-pc1.markwaite.net/gitweb/?p=|\[$class: 'GitWeb']|
|github.com/|https://github.com/|\[$class: 'GithubWeb']|
|mark-pc1.markwaite.net:/var/lib/git/|http://mark-pc1.markwaite.net/gitweb/?p=|\[$class: 'GitWeb']|
|localhost:10022/|http://localhost:10080/|\[$class: 'GogsGit']|\[userRemoteConfigs: \[\[credentialsId: 'aad288c5-ea8e-4484-8e2d-9dc7abab7910']]]|
- > finds clonebase = mark-pc1.markwaite.net/git/, repositorypath = foo, webbase = http://mark-pc1.markwaite.net/gitweb/?p=, browser = \[$class: 'GitWeb']
- > website = webbase + repositorypath = http://mark-pc1.markwaite.net/gitweb/?p=foo
- > browserurl = http://mark-pc1.markwaite.net/gitweb-/?p=foo-
- > browser = \[$class: 'GitWeb', repoUrl: 'http://mark-pc1.markwaite.net/gitweb']
- > add the browser and "other Stuff" fields to the checkout options (only those that arent explicitely set in a Job)

I think a really big portions of the are covered with this rather simple scheme. Of yourse you can always have totally unrelated clone URS and webpages, and existing installations should still use the values specified in the jobs.
But it would be a nice way of having a configurable default.

* the scp URLs [user@]host.xz:path/to/repo.git/ and raw file URLs /path/to/repo.git/ schould be internally converted to the "protocol URLS" for consistent clone URL syntax and simpler matching. 
* Matching a *clonebase* needs to take the longest match, so you could override a Server default for single repositories.

stephen.alan.connolly@gmail.com (JIRA)

unread,
Feb 24, 2017, 7:16:01 AM2/24/17
to jenkinsc...@googlegroups.com

Is this not already possible as setBrowser has a @DataBoundSetter https://github.com/jenkinsci/git-plugin/commit/a55c66cd908eb1b697e86572ae18fe203003155b

This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

stephen.alan.connolly@gmail.com (JIRA)

unread,
Feb 24, 2017, 7:17:01 AM2/24/17
to jenkinsc...@googlegroups.com
Stephen Connolly resolved as Fixed
 

I claim this is already fixed (at least with git-plugin 3.0.5 and 2.6.5 and some other versions too but would need checking). Please reopen if I am incorrect

Change By: Stephen Connolly
Status: Open Resolved
Resolution: Fixed

mark.earl.waite@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:34:26 PM10/22/19
to jenkinsc...@googlegroups.com
Mark Waite closed an issue as Fixed
Change By: Mark Waite
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages