how do I modify one option in scm.getUserRemoteConfigs without having to manually set all the options?

76 views
Skip to first unread message

red 888

unread,
Aug 21, 2019, 4:56:41 PM8/21/19
to Jenkins Users

in my jenkins pipeline i have this:


checkout([$class: 'GitSCM',
          branches: [[name: "${env.BRANCH_NAME}"]],
          doGenerateSubmoduleConfigurations: false,
          extensions: [
              [$class: 'SubmoduleOption',
               disableSubmodules: false,
               parentCredentials: true,
               recursiveSubmodules: true,
               reference: '',
               trackingSubmodules: true],
              [$class: 'CloneOption', timeout: config.timeout],
              [$class: 'CheckoutOption', timeout: config.timeout],
              [$class: 'GitLFSPull']
          ],
          submoduleCfg                     : [],
          userRemoteConfigs: [[
              //scm.userRemoteConfigs,
              refspec: '+refs/tags/*:refs/remotes/origin/tags/*'
          ]]
])


I just want to modify the refspec and use the rest of the defaults in scm.userRemoteConfigs. How can I do that without having to manually set all of them because Im no longer just passing in scm.userRemoteConfigs


Im trying to get jenkins to trigger a build when it sees a new tag (like it does with new branches) right now it indexes and gets the new tag but doesn't run a build

Mark Waite

unread,
Aug 21, 2019, 10:56:32 PM8/21/19
to Jenkins Users
I think you can assign the original to a new variable, then modify only the precise portions that need to be changed.

Like this:

// Narrow the respec to only this branch
def branch = 'JENKINS-59016'
def myRemoteConfigs = scm.userRemoteConfigs
myRemoteConfigs[0].refspec = "+refs/heads/${branch}:refs/remotes/origin/${branch}"

Then use the new variable as the value as in:

   userRemoteConfigs: myRemoteConfigs

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7e5c1679-a40c-4364-b149-282008953df5%40googlegroups.com.


--
Thanks!
Mark Waite
Reply all
Reply to author
Forward
0 new messages