问题描述
我将AWS CodeBuild设置为从GitHub自动构建.其他CI服务为分支机构提供了一个环境变量,但是我找不到适用于AWS CodeBuild的环境变量.有一个CODEBUILD_SOURCE_VERSION
设置为pr/7
,其中7
是请求请求号或git commit sha.
I'm setup AWS CodeBuild to build automatically from GitHub. Other CI services provide an environment variable for the branch, but I can't find one for AWS CodeBuild. There is a CODEBUILD_SOURCE_VERSION
that is set to either pr/7
where 7
is the pull request number or the git commit sha.
鉴于commit sha,我一直在尝试获取分支名称,但到目前为止还没有运气.
Given the commit sha, I've been trying to get the branch name, but no luck so far.
git branch --contains <commitsha>
不起作用,因为它是一个分离的头.如何从CodeBuild获取提交的git分支?
git branch --contains <commitsha>
doesn't work because it is a detached head. How do I get the git branch for the commit from CodeBuild?
推荐答案
您可以运行:
git branch -a --contains <sha>
-a
表示所有分支.如果您的sha没有分支(在某些情况下可能会发生),您将看不到任何东西.
-a
means all branches. If your sha is in no branch, which could happen in some cases, you won't see anything.
这篇关于获取适用于AWS CodeBuild的GitHub git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!