Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71132

Git plugin: fetch and prune tags on submodules

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Trivial Trivial
    • git-plugin

      There is no option to fetch and prune tags on all submodules in Jenkins.

      In our environment, it happens in rare cases that tags are force-pushed on the main repo and on submodules. We did not find any way to reflect the actual tags before build using Jenkins, except with a full repository wipeout.

      Also we have a case where a new tag on the submodule repository was not present on our builder at build time.

      We tried using a command such as git fetch --prune origin "refs/tags/:refs/tags/ in the build steps, but this fails as the credentials cannot be used at that stage.

          [JENKINS-71132] Git plugin: fetch and prune tags on submodules

          Mark Waite added a comment -

          The withCredentials() block in Pipeline will allow you to use arbitrary git commands with a username / password credential (https access to git repositories). The sshAgent block will allow you to use arbitrary git commands with private key credentials. Can you try one of those for your case to see if can workaround the issue?

          Mark Waite added a comment - The withCredentials() block in Pipeline will allow you to use arbitrary git commands with a username / password credential (https access to git repositories). The sshAgent block will allow you to use arbitrary git commands with private key credentials. Can you try one of those for your case to see if can workaround the issue?

          Benoît added a comment -

          Hello markewaite, thank you for your answer.

          I now have a mix like this in my DSL script:

          job('job_name') {
              description('descr')
          
              wrappers {
                  sshAgent(GIT_CREDENTIALS_KEY)
              }
          
              scm {
                  git {
                      remote {
                          name('origin')
                          credentials(GIT_CREDENTIALS_KEY)
                          url('git@<redacted>:<repo>')
                      }
                      branch('*/main')
                      extensions {
                          cleanAfterCheckout()
                          pruneTags {
                              pruneTags(true)
                          }
                          submoduleOptions {
                              parentCredentials(true)
                              recursive(true)
                          }
                      }
                  }
              }
          
              steps {
              powershell('''
          Set-Location -Path ${ENV:WORKSPACE}
          & git.exe submodule foreach git.exe fetch --prune origin "+refs/tags/*:refs/tags/*"
          
          <rest of the build commands>
          ''')
          }

          With this configuration, all steps performed by the Git plugin work, but the custom git.exe command that prunes submodule tags has fails with a public key error.

          Is there something I am missing here?

          Thank you.

          Benoît added a comment - Hello markewaite , thank you for your answer. I now have a mix like this in my DSL script: job( 'job_name' ) { description( 'descr' ) wrappers { sshAgent(GIT_CREDENTIALS_KEY) } scm { git { remote { name( 'origin' ) credentials(GIT_CREDENTIALS_KEY) url( 'git@<redacted>:<repo>' ) } branch( '*/main' ) extensions { cleanAfterCheckout() pruneTags { pruneTags( true ) } submoduleOptions { parentCredentials( true ) recursive( true ) } } } } steps { powershell(''' Set-Location -Path ${ENV:WORKSPACE} & git.exe submodule foreach git.exe fetch --prune origin "+refs/tags/*:refs/tags/*" < rest of the build commands> ''') } With this configuration, all steps performed by the Git plugin work, but the custom git.exe command that prunes submodule tags has fails with a public key error. Is there something I am missing here? Thank you.

          Mark Waite added a comment -

          I don't know the Job DSL syntax, so can't comment on the correctness of that job definition. Since the powershell step is not inside the sshAgent wrapper, I would be surprised if the sshAgent wrapper is being applied to the powershell step. Could you check within the Jenkins job definition to confirm that the sshAgent wrapper is around the powershell step in the job definition?

          Mark Waite added a comment - I don't know the Job DSL syntax, so can't comment on the correctness of that job definition. Since the powershell step is not inside the sshAgent wrapper, I would be surprised if the sshAgent wrapper is being applied to the powershell step. Could you check within the Jenkins job definition to confirm that the sshAgent wrapper is around the powershell step in the job definition?

          Mark Waite added a comment -

          I don't plan to implement this in the git plugin

          Mark Waite added a comment - I don't plan to implement this in the git plugin

            Unassigned Unassigned
            benoit_mortgat Benoît
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: