我看了这个问题,它有些类似但并不完全相同。那里的问题在于标签没有被正确推送。
我目前正在使用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)
}
}
}
}
}
}
}
}
}
一些配置数值来自于
BuildProjects
。
运行 Jenkins 时,我发现它会获取标签: > git fetch --tags --progress -- ssh://git@git.my-company.net/tools.git +refs/heads/*:refs/remotes/origin/* # timeout=1
实际上,我可以在使用an时在我的Jenkinsfile中输出标签。
sh "git tag"
块级元素。但使用
sh "git describe --tags"
提供
fatal: No tags can describe '<Commit hash>'.
Try --always, or create some tags.
我在某处读到,这可能是由于稀疏检出引起的:标签和当前HEAD之间的提交可能已经丢失。仔细检查后,我在我的日志中发现
> git config core.sparsecheckout # timeout=10
> git checkout -f <Commit hash> # timeout=10
在上面展示的git fetch
行之后,立即执行。看来我的JobDSL配置不被尊重。有什么想法吗?