我的一个Jenkins管道作业应该考虑当前正在构建的提交上的标记。但似乎最顶层提交的标签在构建时不可用。
假设我有一个简单的历史,有三次提交:
my_commit_to_build (tagged v2)
|
v
another_commit (tagged v1)
|
v
initial_commit
我的管道脚本包含这个checkout-step:
checkout(
changelog: false,
poll: false,
scm: [
$class : 'GitSCM',
userRemoteConfigs: [
[
url : <SCM_URL>,
credentialsId: <CREDENTIALS_ID>,
refspec : <REFSPEC_TO_BUILD>
]
],
branches : [
[
name: <REFSPEC_TO_BUILD>
]
],
extensions : [
[$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']],
[$class: 'LocalBranch', localBranch: <LOCAL_BRANCH_NAME>],
[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
[$class: 'PruneStaleBranch'],
[$class: 'CleanCheckout']
]
]
)
这将导致作业运行以下命令:
Cloning the remote Git repository
Cloning repository <SCM_URL>
> git init /home/jenkins/workspace/<WORKSPACE> # timeout=10
Fetching upstream changes from <SCM_URL>
> git --version # timeout=10
using GIT_SSH to set credentials SSH Key for <USER>
> git fetch --tags --progress <SCM_URL> +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url <SCM_URL> # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url <SCM_URL> # timeout=10
Pruning obsolete local branches
Fetching upstream changes from <SCM_URL>
using GIT_SSH to set credentials SSH Key for <USER>
> git fetch --tags --progress <SCM_URL> --prune
> git rev-parse <REV>^{commit} # timeout=10
Checking out Revision <REV> (<LOCAL_BRANCH_NAME>)
> git config core.sparsecheckout # timeout=10
> git checkout -f <REV>
> git branch -a -v --no-abbrev # timeout=10
> git checkout -b <LOCAL_BRANCH_NAME> <REV>
Commit message: "my_commit_to_build"
Cleaning workspace
> git rev-parse --verify HEAD # timeout=10
Resetting working tree
> git reset --hard # timeout=10
> git clean -fdx # timeout=10
现在,当我检查repo的本地副本以查找历史记录中最顶层提交和最后一次提交的标记时,我得到了以下内容:
> git --no-pager tag -l --points-at=HEAD
> git describe --abbrev=0 --tags
v1
> ...
我已经尝试从fetch命令和sparse
签出中删除prune
,但两者都不起作用(我对这两个命令也没有任何希望……)。
有没有人知道我应该如何调整我的签出步骤,以便在构建时标签可用?
提前感谢!
发布于 2018-02-01 23:33:05
这可能是一个更好的评论,但我还不能添加它们。
我在一个类似的存储库上进行了测试,除了BuildChooserSetting之外,它具有相同的扩展名,并且它如预期的那样工作。
您确定您要检查的分支包含该标记吗?另外,git tag
的输出是什么
https://stackoverflow.com/questions/48529734
复制相似问题