简体   繁体   English

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

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

One of my Jenkins pipeline jobs should consider a tag on the commit that is currently build. 我的Jenkins管道作业之一应考虑当前正在构建的提交上的标记。 But it seems the tag on the topmost commit is not available at build time. 但是似乎最顶层提交上的标签在构建时不可用。

Let's say I have a simple history with three commits: 假设我有三个提交的简单历史记录:

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

My pipeline script contains this 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']
        ]
    ]
)

This results in the folowing commands run by the job: 这导致作业运行以下命令:

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

When I now check the local copy of the repo for the tag on the topmost commit and the last commit found in the history, I get the following: 现在,当我检查存储库的本地副本中历史记录中最上面的提交和最后一次提交时的标记时,将得到以下信息:

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

I already tried removing the prune from the fetch command and the sparse checkout, but both didn't help (I hadn't any hope with those two anyway...). 我已经尝试prune fetch命令和sparse签出中删除prune ,但是两者都没有帮助(无论如何,我对这两个都没有希望...)。

Has anyone any idea how I should adapt my checkout step, so that the tag is available when building? 有谁知道我应该如何调整我的结帐步骤,以便在构建标签时可用?

Thanks in advance! 提前致谢!

This would probably be better as a comment but I can't add them yet. 作为注释,这可能会更好,但是我还不能添加它们。

I tested on a similar repo with the same extensions except for BuildChooserSetting and it worked as expected. 除了BuildChooserSetting之外,我在具有相同扩展名的类似存储库上进行了测试,并且按预期工作。

Are you sure the branch you're checking out contains that tag? 您确定要签出的分支包含该标签吗? Also, what is the output of git tag ? 另外, git tag的输出是什么?

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

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