-
Improvement
-
Resolution: Unresolved
-
Minor
-
Powered by SuggestiMate
Currently when checking out multiple repositories or a single repository with submodules the Git plugin only displays the commit sha(s) and branch name(s) for each of the repositories being checked out on the job details page and as part of the Git Build Data.
It would be useful to have the Organization/Project and Repository name(s) displayed alongside the commit sha(s) and branch name(s). This makes it easier to associate the changes to the repository.
- is related to
-
JENKINS-29840 when workflow uses multiple git repos the "git build data" and "tags" become next to useless.
-
- Open
-
-
JENKINS-47689 Repository names missing in currentBuild.changeSets nor display in Change log page when using multiple repositories
-
- Open
-
- relates to
-
JENKINS-38676 git summary should show the repository URL
-
- Closed
-
[JENKINS-54868] Display Organization/Project and Repository name(s) on the job details page
Nice xiongkezhi, your trying seems great.
Instead the repository name which seems difficult to get.
Why do not write the URL of git remote?
xiongkezhi: How do you managed to get the information in your UI (screenshot)?
mrlov This is a PR from the beginning of this year which I have closed, the PR is here: https://github.com/jenkinsci/git-plugin/pull/839/files
Hey! I would like to work on this issue. I don't understand why the above pull request has not been merged.
Format of github url:
By using regular expression, can I just format the url of the project by getting the organization name and repo name.
After getting the organization name and repo name, I can then display it in the UI.
Is this way of approaching the issue the correct or is there any other way of solving it?
Thank You
By using regular expression, can I just format the url of the project by getting the organization name and repo name.
Conceptually yes, though you'll either need a very sophisticated regular expression or you'll need to process the repository URL multiple times for the different forms of repository URLs.
Example URLs to be handled include:
- ssh://markwaite@vs-ssh.visualstudio.com:22/DefaultCollection/_ssh/elisp
- ssh://git@github.com/MarkEWaite/tasks.git
- ssh://git.assembla.com/git-plugin.bin.git
- https://www.assembla.com/spaces/git-plugin/git-2/
- https://markwaite.visualstudio.com/_git/elisp
- https://markwaite.visualstudio.com/DefaultCollection/_git/elisp
- https://markwaite.visualstudio.com/DefaultCollection/elisp/_git/elisp
- https://markwaite:password-here@markwaite.visualstudio.com/DefaultCollection/_git/elisp
- https://markewaite:password-here-also@bitbucket.org/markewaite/tasks.git
- https://markewaite:password-here-as-well@bitbucket.org/markewaite/bin.git
- https://markewaite@bitbucket.org/markewaite/tasks.git
- https://markewaite@bitbucket.org/markewaite/git-client-plugin.git
- https://markewaite@bitbucket.org/markewaite/bin.git
- https://MarkEWaite:also-a-password@gitlab.com/MarkEWaite/tasks.git
- https://MarkEWaite:another-password@github.com/MarkEWaite/tasks.git
- https://MarkEWaite:yes-this-is-a-password@github.com/MarkEWaite/bin.git
- https://jenkins-git-plugin.git.beanstalkapp.com/git-client-plugin.git
- https://gitlab.com/MarkEWaite/tasks.git
- https://gitlab.com/MarkEWaite/tasks
- https://gitlab.com/MarkEWaite/bin
- https://github.com/MarkEWaite/tasks.git
- https://github.com/MarkEWaite/bin.git
- https://git.assembla.com/git-plugin.bin.git
- https://bitbucket.org/markewaite/tasks.git
- https://bitbucket.org/markewaite/git-client-plugin.git
- https://bitbucket.org/markewaite/bin.git
- git@jenkins-git-plugin.git.beanstalkapp.com:/jenkins-git-plugin/git-client-plugin.git
- git@gitlab.com:MarkEWaite/tasks.git
- git@github.com:MarkEWaite/tasks.git
- git@github.com:MarkEWaite/bin.git
- git@git.assembla.com:git-plugin.bin.git
- git@bitbucket.org:markewaite/tasks.git
- git@bitbucket.org:markewaite/bin.git
Thanks Mark. Working on it. Are these the only final urls or are there more?
hrushi20 those are example URLs. There are many, many more URLs than those, but the patterns described in those URLs are a reasonable sample of the allowed formats of git repository URLs. Refer to the git protocols documentation for more details.
The thing is I am trying to generalize the regex for all use cases. If I don't proceed with regex then I need to use switch case checking condition for every kind of url organization ie (github,gitlab,Bitbucket etc).
Thank You.
It might be best to have a list of regular expression patterns in the global configuration. Then the administrator could define patterns like
git@bitbucket\.org:(?<group>[^/?#]+)/(?<repo>[^/?#]+)\.git https://([^@/]+@)?(?<group>[^./?#]+)\.visualstudio\.com/DefaultCollection/_git/(?<repo>[^/?#]+)
Probably just a few patterns would suffice for each Jenkins instance. Put some sample patterns in the help text and let the administrator copy from there. This way, the feature would also work with on-premises servers that can have arbitrary hostnames.
If the URL includes a password, then it might be good to delete that in Java code before even considering the patterns.
kon are you saying that the administrator(ie. the user) will enter the regex by themself. What exactly does global configuration stands for here? Is it the web ui interface?
Hey! This regex can be used for all project with github, gitlab and Bitbucket urls. It supports ssh/http and git protocol url. Can you check if it defies any string url. This doesn't support visualstudio.
(?!.*visualstudio)^(\w+(://|@))(\w+.*(com|org)(:|/))(?<group>.+)/*(?<repo>.+)$
Thank You
hrushi20 I believe that kon is suggesting that it would be helpful to have a global configuration option in the git plugin that would allow the administrator to define the regular expression and the replacement text for those cases where the user runs their own git server. That would allow support of servers like:
- https://developers.example.com/gitea
- https://sources.example.com/gitlab
- https://code.uk.example.com/gogs
The git plugin already has a global configuration page, so this would be an addition to already existing configuration settings.
markewaite. The global config page is the page when we configure our project right?
Do I create an Input field for every repository or single input for all repository regex?
The global configuration page that I was referencing is at
https://your-jenkins.example.com/configure
I got the global configuration page.
I'll create an input tag which takes in the regex and then parses the url of the repository and display the Org Name/Repo name. The implementation can be tweaked based on the requirements.
I am referring this link for configuring jelly with jenkins.
Thank You
I'm a little confused about the intent of this JIRA, so just hoping to get clarity and validate requirements, given the ubiquitous utilization of the git plugin. I also don't pretend to be an expert on Git, the git-plugin, nor regex.
PRESENT STATE: Status page and Git Build Data page show only the commit ref and the branch name.
Git supports a variety of connection types/protocols (git:, http(s):, ssh:, ftp(s):, file: ), and the path/to/repo may take various forms.
DESIRED STATE: Show the OrgName/RepoName. Or, given the nuances to come, [path/to/repo/]<repo_name>, or repo_url minus host_url;
This would be equivalent to the Jenkins JOB_URL, minus the JENKINS_URL, call it the REPO_FULLNAME with the GITHOST_URL removed.
I'd be interested in seeing the REPO_FULLNAME as just one of our instances connects to over 600 different repos on a variety of hosts.
I often find to click configure to get validate the repo (and get the link to navigate), but at least seeing the repo name would cut significant toil.
I am undecided whether an option to also show the GITHOST_NAME (not the GITHOST_URL) would be necessary to disambiguate.
Our hosts include GitHub, Gitlab, AzureDevOps Server/TFS (on-prem), Gogs some just file://, (markewaite has listed more (above), like Assembla and BitBucket). Azure DevOps Server nomenclature is actually:
http://tfs.mycorp.com/tfs/<TeamCollection>/<TeamProject>/_git/<RepoName>, so it's more than just <OrgName>/<Reponame>.
Some of our host servers end in an internal domain which is not (com|org), We also don't need to supply a FQDN either; HOST will suffice.
Thus the solution is more akin to: how to remove the HOST_URL given the wide variety of possible connection formats, not exclusively extract <OrgName>/<RepoName>.
Assume the displayed REPO_FULLNAME would exclude any ".git" extension and in the case of AzureDevOps,, the "/_git" separator.
The solution should be able to handle multiple GITHOST_URL for a given instance.
It should be able to handle all the scenarios described, plus any nuances other host applications might throw.
As admin, I also really don't want to have to maintain a regex property list for the users.
Not a regex expert, but this regex ".(:[^/]|@|\/\/)([^/])\/"works to match the leading GITHOST_URL portion for the examples Mark provided, except for the one without a Assembla one without slash (git@git.assembla.com:git-plugin.bin.git).
Any regex that strips the ending ".git" should not exclude a reponame ending in git (ie: https://github.com/git/git.git}}) or with git in the name (eg: https://github.com/git/git.github.io.git ) or other oddballs (eg: https://github.com/git/git-scm.com.git or http://tfs.mycorp.com/tfs/Collection/TeamProj/_git/automation_git; ). It should also properly handle the "/_git" or "/_ssh" MS throws at you.
Not 100% sure this helps add clarity or validate the requirements, but I hope it at least identified some gotchas.
(Removed clickable link remarks; seems it's a bad config / old instance my part).
PRESENT STATE: Status page and Git Build Data page show only the commit ref and the branch name.
The repository URL was added to src/main/resources/hudson/plugins/git/util/BuildData/summary.jelly in JENKINS-38676 PR #1067. That was released in Git plugin 4.7.2 in June 2021.
Is this issue a request to replace the full URL with the Organization/Project and Repository names only? If so, I think it should be opt-in.
Hey I have submitted a pull request. This is a basic version on which we can add the required features. We can discuss about the further implementation of the feature.
https://github.com/jenkinsci/git-plugin/pull/1226
Thank You
Hey! I have a doubt regarding testing. I created a global regex input field on the website. While testing, how do I create a global regex input and add it to the global configuration so that I can use it to get the organization name and repo name.
As the objective of this feature is to display the OrgName/RepoName on the Job Build Log page, you'd have to create a set of dummy build logs that reflect all the possible combinations of legitimate Git connection types/protocols (git:, http(s):, ssh:, ftp(s):, file: ), to the various Git remote host types, both without an the permutations of supported Org structures, including things like a plain file: or plain remote connection, with and without password or token, etc. (pay attention to Azure Devops format which uses an unconventional format, with "/_git" ). Then test cases will validate the configured regex produce the expected results.
Your requirements should be able to be validated passing a known set of inputs like Mark Waite listed and I added to. Segmented test cases should validate each configuration target type separately for the various connection options, or otherwise partitioned.
One interesting feature is used in the REST List Parameter plugin and Build Failure Analyzer. Both plugins support a Test validation option as part of the configuration.
ianw , can you go through my draft pull request. Not sure how to create dummy build logs. I am actually new to testing and finding some difficulties. I feel the way I implemented the Global configuration is not correct. The global configuration regex takes in a single input regex and validates all the urls according to my implementation. Is the global configuration regex only for custom domains? Also Internally do I need to create a regex for default git urls.
Pull request: link
hrushi20, would just like to chip in and say that the implementation can vary depending on your conception of it and how it will be implemented. It could be either a list of URL regex patterns or a single URL regex pattern. However, if you are aiming to use one single URL regex pattern than be aware that this might be harder to maintain and use down the line. Other factors to consider would be customisability and usability as a global option as suggested above.
For testing maybe the list of example URLs could be checked one by one for assertion to be `true`. You will need to at least test the organisation and project repo in two separate tests for example. If you are testing a list of possible URL regex patterns, be sure to classify the URLs accordingly and write a test for each category. It is up to you to propose a viable solution, so we are only making suggestions to you. You have the freedom to decide ultimately how you would like to approach the problem.
Multiple Regex can be added in the global configuration. Each regex needs to be separated by `&&&` for now. All urls stated by markewaite are running successfully. Looking for edge cases to solve. I'll try adding more test cases related to azure and other protocols.
I have successfully tried to add the organization/project name and made it looks like this.
But as you can see above, I still haven't found the right way to get the repository name. As far as I know, there is not a specific defined 'name' for a git repository. For a local repository, the name should be the root folder name; or if it is a GitHub repo, the only way to get the repository is to parse the repository address. Any further suggestions? Thanks very much!