How to get repo name in jenkins pipeline

I use the Jenkins Scripted Pipeline, which uses the Groovy style script, and created a Jenkins file to describe the pipeline. I need to create a workspace with a folder name similar to git repo name, and then check the code in the workspace folder. My question is, before doing checkout scm, is there a way to find out the git repo name or the git repository url?

+4
source share
1 answer
String determineRepoName() {
    return scm.getUserRemoteConfigs()[0].getUrl().tokenize('/')[3].split("\\.")[0]
}

This relatively ugly code is what I use to get repoName. The key is that the repo url is stored in:

scm.getUserRemoteConfigs () [0] .getUrl ()

, , .


: String determineRepoName() { return scm.getUserRemoteConfigs()[0].getUrl().tokenize('/').last().split("\\.")[0] }

(https://domain/project/subproject/repo ssh git repo, // .

+6

Source: https://habr.com/ru/post/1683718/


All Articles