Jenkins pipeline get repository url variable under pipeline script from scm

Jenkinsjenkins-pipeline

i'm using Jenkins file that located in my git repository.
I have configured new job using the pipeline script from scm that point to my jenkinsfile. I'm trying to use in my Jenkins file pipeline script the git module in order to pull my data from my git repo without configure pre static variable and just to use the variable of the repository URL under pipeline script from scm that already was configured in my job .
There is a way to get somehow the variable Repository URL
from this plugin without using parameters in my Jenkins pipeline script.

I have already tried the environment variable GIT_URL and other stuff that related to git from here but this didn't work.

pipeline script from scm

Best Answer

You can find all information about scm in scm variable (instance of GitSCM if you are using git). You can get repository URL this way

def repositoryUrl = scm.userRemoteConfigs[0].url  

But if you just want to checkout that repository you can simply invoke checkout scm without needing to specify anything else. See checkout step

Related Topic