1

This is duplicated with: how to know which git branch triggered the jenkins job, however the answer below it cannot solve, which is:

commit = checkout scm
println commit.GIT_URL

above code could just return the GIT_URL that which repository the Jenskinsfile on.

So I have to answer again:

My job polling three GIT repository:
repos-A, repos-B, repos-C
with follow code:

triggers {
    pollSCM '* * * * *'
}
checkout changelog: false, scm: [$class: 'GitSCM', branches: [[name: 'refs/heads/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [...]
checkout changelog: false, scm: [...]
checkout changelog: false, scm: [...]

Any of their commit will trigger my job, then during the job execution, I need to tell which repository trigger the job, to determine different stage to going on.

How can I get the repository info?

Du Ying
  • 11
  • 2
  • This might help: https://stackoverflow.com/questions/45684941/how-to-get-repo-name-in-jenkins-pipeline – ANIL Nov 09 '18 at 10:42
  • 1
    Hi ANIL,thanks for your reply, but I've tried this solution before, `scm.getUserRemoteConfigs()[0].getUrl()` will always reply the repository which jenkinsfile be stored, it cannot tell which is the triggered repository – Du Ying Nov 12 '18 at 02:30
  • @DuYing, id you find the answer finally? – Vinay Nov 17 '22 at 21:46

0 Answers0