繁体   English   中英

Jenkins管道中的Git Checkout错过了commit的标签

[英]Git checkout in Jenkins pipeline misses commit's tag

我的Jenkins管道作业之一应考虑当前正在构建的提交上的标记。 但是似乎最顶层提交上的标签在构建时不可用。

假设我有三个提交的简单历史记录:

 my_commit_to_build (tagged v2)
            |
            v
   another_commit (tagged v1)
            |
            v
      initial_commit

我的管道脚本包含以下结帐步骤:

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

现在,当我检查存储库的本地副本中历史记录中最上面的提交和最后一次提交时的标记时,将得到以下信息:

> git --no-pager tag -l --points-at=HEAD
> git describe --abbrev=0 --tags
v1
> ...

我已经尝试prune fetch命令和sparse签出中删除prune ,但是两者都没有帮助(无论如何,我对这两个都没有希望...)。

有谁知道我应该如何调整我的结帐步骤,以便在构建标签时可用?

提前致谢!

作为注释,这可能会更好,但是我还不能添加它们。

除了BuildChooserSetting之外,我在具有相同扩展名的类似存储库上进行了测试,并且按预期工作。

您确定要签出的分支包含该标签吗? 另外, git tag的输出是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM