How to capture last part of the git url using shell script?

Pritish

I am writing a Jenkins pipeline. I am trying to capture last part of the git url without the git extension. For instance: https://github.hhhh.com/aaaaaa-dddd/xxxx-yyyy.git. I want only xxxx-yyyy to be returned. Below is my code:

String getProjectName() {
    echo "inside getProjectName +++++++"
    # projectName = sh(
    #         script: "git config --get remote.origin.url",
    #         returnStdout: true
    # ).trim()
    def projectName= sh returnStdout:true, script: '''
    #!/bin/bash
    GIT_LOG = $(env -i git config --get remote.origin.url)
    echo $GIT_LOG
    basename -s .git "$GIT_LOG"; '''
    echo "projectName: ${projectName}"
    return projectName
}

PS: Please ignore the commented lines of code.

Cyrus

No space before and after =:

x='https://github.hhhh.com/aaaaaa-dddd/xxxx-yyyy.git'
basename "$x" .git

Output:

xxxx-yyyy

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get the last part of '/' separated string in shell script

How to remove the last part of url?

How to read user last email using a shell script?

Capture the last subfolder of the URL to redirect using htaccess

backup git using shell script

How to capture the Gradle exit code in a shell script?

HttpClient 4 - how to capture last redirect URL

How to clone a private git repository using a initialization shell script

Get last part of url using a regex

Linux Shell Script cut last part of variable which contains a path

How to get the URL from a file using a shell script

How to extract protocols (http)[s] to check url using shell script

Shell script : How to cut part of a string

how to run a tunnel in the background as part of a shell script

How to log output of a part of a shell script

How to remove the last part of a string url in PHP

How to ignore last url part with react router?

How to remove last part of url in PHP

How to regex last part of URL only?

pcre. How to get last part of url

How to determine the last part of URL with jq?

How to remove last part of my URL with .htaccess?

URL Redirect Rule - Regex - How To Capture Part Of URL

How to capture the output of a Julia script while the script is running in a shell?

How to capture this specific string using regular in shell?

Shell script self update using git

How to fetch last argument and stop before last arguments in shell script?

How to determine the line number of the last occurrence of a string in a file using a shell script?

How do I get an acceptable last modified timestamp for my Jekyll site using a shell script?