git describe --tags 不适用于 Jenkins 管道构建

arn*_*rne 5 git jenkins jenkins-job-dsl

我见过这个问题,它朝着类似的方向发展,但并不完全。问题在于标签没有正确推送。

我目前正在使用 Jenkins 构建我的 python 项目setuptools_scm,它基本上用于git describe获取(或多或少)合理的版本号,即使不在标签上。管道是使用 JobDSL 中的种子作业定义的,如下所示(缩写为了解要点):

import BuildProjects

BuildProjects.build_projects.each { def bproject ->
   multibranchPipelineJob("tool/${bproject}") {
      branchSources {
         branchSource {
            source {
               git {
                  id('tool_${bproject}')
                  remote("${BuildProjects.scmBaseLocation}/${bproject}.git")
                  credentialsId(BuildProjects.scmUser)
                  traits {
                     gitBranchDiscovery()
                     gitTagDiscovery()
                     cloneOptionTrait {
                        extension {
                           shallow(false)
                           noTags(false)
                           reference('grmblwrx')
                           timeout(1)
                        }
                     }
                  }
               }
            }
         }
      }

   }
}
Run Code Online (Sandbox Code Playgroud)

一些配置值取自BuildProjects.

运行 jenkins 时,我看到它获取标签:

 > git fetch --tags --progress -- ssh://git@git.my-company.net/tools.git +refs/heads/*:refs/remotes/origin/* # timeout=1
Run Code Online (Sandbox Code Playgroud)

事实上,当我使用 Jenkinsfile 输出标签时,我可以看到标签

sh "git tag"
Run Code Online (Sandbox Code Playgroud)

堵塞。但是使用

sh "git describe --tags"
Run Code Online (Sandbox Code Playgroud)

fatal: No tags can describe '<Commit hash>'.
Try --always, or create some tags.
Run Code Online (Sandbox Code Playgroud)

我在某处读到这可能是由于结帐稀疏造成的:标签和当前 HEAD 之间的提交可能丢失。经过仔细检查,我在日志中发现

> git config core.sparsecheckout # timeout=10
> git checkout -f <Commit hash> # timeout=10
Run Code Online (Sandbox Code Playgroud)

就在git fetch上面显示的行之后。似乎不知何故我在 JobDSL 中的配置没有得到尊重。有任何想法吗?

arn*_*rne 3

自从我发布问题后,我们更新了 Jenkins 实例和一些插件,特别是 git 插件。出于某种原因,它现在“简单有效”。我无法在没有很多麻烦的情况下重现旧设置,因此我无法轻易找出导致“修复”的原因。