how to get repo name in Jenkins pipeline

后端 未结 1 1930
天命终不由人
天命终不由人 2020-12-30 11:25

I\'m using Jenkins Scripted Pipeline that uses Groovy style scripting, and created a Jenkinsfile to describe the pipeline. I need to create the workspace with the folder nam

相关标签:
1条回答
  • 2020-12-30 11:56
    String determineRepoName() {
        return scm.getUserRemoteConfigs()[0].getUrl().tokenize('/')[3].split("\\.")[0]
    }
    

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

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

    from there you need to do some string ops to get what you want.


    Update:

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

    This works also for repositories with a deeper hierarchy (https://domain/project/subproject/repo or ssh git repo which does not contain the two // at the start.

    0 讨论(0)
提交回复
热议问题