Setting the name of the git remote repository

252 views
Skip to first unread message

Misty Stanley-Jones

unread,
Apr 21, 2015, 10:33:14 PM4/21/15
to job-dsl...@googlegroups.com
I am using a fairly old version of the plugin (1.20) and updating is not up to me. I'm having trouble setting the name of the repository for my Github repository. Here is my scm block:

        scm {
          git ("http://my-github/my-org/${Repository}.git", "*/${Branch}") { node ->
            def remoteConfig = node/userRemoteConfigs/'hudson.plugins.git.UserRemoteConfig'
            remoteConfig << refspec("+refs/heads/${Branch}:refs/remotes/origin/${Branch}")
            remoteConfig << name("origin")
            node / localBranch << "${Branch}"
          }
        }


With the name("origin") line, not only do I not get the result I want, but the name of the job is overridden to be "origin" as well. If I leave off the name("origin") line, the refspec DOES get generated correctly. The URL does not!It looks to me in the XML like the name and refspec should be added in the same way.

Here is the resulting XML from the config above:

<scm class="hudson.plugins.git.GitSCM">
  <configVersion>2</configVersion>
  <disableSubmodules>false</disableSubmodules>
  <recursiveSubmodules>false</recursiveSubmodules>
  <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
  <authorOrCommitter>false</authorOrCommitter>
  <clean>false</clean>
  <wipeOutWorkspace>false</wipeOutWorkspace>
  <pruneBranches>false</pruneBranches>
  <remotePoll>false</remotePoll>
  <ignoreNotifyCommit>false</ignoreNotifyCommit>
  <gitTool>Default</gitTool>
  <skipTag>false</skipTag>
  <userRemoteConfigs>
    <hudson.plugins.git.UserRemoteConfig>origin</hudson.plugins.git.UserRemoteConfig>
  </userRemoteConfigs>
  <branches>
    <hudson.plugins.git.BranchSpec>
      <name>*/master</name>
    </hudson.plugins.git.BranchSpec>
  </branches>
  <localBranch>master</localBranch>
</scm>


Here is the XML when I leave off the name("origin"):

<scm class="hudson.plugins.git.GitSCM">
  <configVersion>2</configVersion>
  <disableSubmodules>false</disableSubmodules>
  <recursiveSubmodules>false</recursiveSubmodules>
  <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
  <authorOrCommitter>false</authorOrCommitter>
  <clean>false</clean>
  <wipeOutWorkspace>false</wipeOutWorkspace>
  <pruneBranches>false</pruneBranches>
  <remotePoll>false</remotePoll>
  <ignoreNotifyCommit>false</ignoreNotifyCommit>
  <gitTool>Default</gitTool>
  <skipTag>false</skipTag>
  <userRemoteConfigs>
    <hudson.plugins.git.UserRemoteConfig>
      <url>
http://my-github/my-org/my-repo.git</url>
      <refspec>+refs/heads/master:refs/remotes/origin/master</refspec>
    </hudson.plugins.git.UserRemoteConfig>
  </userRemoteConfigs>
  <branches>
    <hudson.plugins.git.BranchSpec>
      <name>*/master</name>
    </hudson.plugins.git.BranchSpec>
  </branches>
  <localBranch>master</localBranch>
</scm>


Here is how I *want* it to look, taken from a job I manually configured.

<scm class="hudson.plugins.git.GitSCM" plugin="g...@1.1.22-SNAPSHOT">
  <configVersion>2</configVersion>
  <userRemoteConfigs>
    <hudson.plugins.git.UserRemoteConfig>
      <name>origin</name>
      <refspec>+refs/heads/master:refs/remotes/origin/master</refspec>
      <url>
http://my-github/my-org/my-repo.git</url>
    </hudson.plugins.git.UserRemoteConfig>
  </userRemoteConfigs>
  <branches>
    <hudson.plugins.git.BranchSpec>
      <name>origin/master</name>
    </hudson.plugins.git.BranchSpec>
  </branches>
  <localBranch>master</localBranch>
  <disableSubmodules>false</disableSubmodules>
  <recursiveSubmodules>false</recursiveSubmodules>
  <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
  <authorOrCommitter>false</authorOrCommitter>
  <clean>false</clean>
  <wipeOutWorkspace>false</wipeOutWorkspace>
  <pruneBranches>false</pruneBranches>
  <remotePoll>false</remotePoll>
  <ignoreNotifyCommit>false</ignoreNotifyCommit>
  <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
  <gitTool>Default</gitTool>
  <submoduleCfg class="list"/>
  <relativeTargetDir/>
  <reference/>
  <excludedRegions/>
  <excludedUsers/>
  <gitConfigName/>
  <gitConfigEmail/>
  <skipTag>false</skipTag>
  <includedRegions/>
  <scmName/>
</scm>


I unset the <name> in an existing job and noticed that there was then a <name/> element. This leads me to believe that I should be overwriting, rather than appending, but I can't actually find the right syntax to do that. If I zero out the refspec, there is an empty <refspec/>, rather than it just not being there either. Hmm.

Matt Sheehan

unread,
Apr 21, 2015, 11:07:31 PM4/21/15
to job-dsl...@googlegroups.com
try using: 

delegate.name("origin")


--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/d6e1e6d0-d5eb-4ff9-b624-50152b6a6c75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Misty Stanley-Jones

unread,
Apr 21, 2015, 11:16:16 PM4/21/15
to job-dsl...@googlegroups.com
Thanks, that worked! I did see the delegate thing in the docs but it was not clear at all how to use it, and I tried a couple false starts. For the record, here is the block that works correctly:

        scm {
          git ("http://my-github/my-org/${Repository}.git", "*/${Branch}") { node ->
            def remoteConfig = node/userRemoteConfigs/'hudson.plugins.git.UserRemoteConfig'
            remoteConfig << refspec("+refs/heads/${Branch}:refs/remotes/origin/${Branch}")
            remoteConfig << delegate.name("origin")
Reply all
Reply to author
Forward
0 new messages