如何区分 bitbucket 管道中的两个 git 分支

How can I diff two git branches in bitbucket pipeline

背景

我想确保推送分支上的所有提交消息都有一个时间日志

即。 add readme /spend 5m

问题

我想获取 bitbucket 管道中两个 git 分支之间的提交差异,

这是我的 yaml 管道配置:

pipelines:
  default:
    - step:
        script:
          - git log $BITBUCKET_BRANCH --oneline --not master

$BITBUCKET_BRANCH 是管道作用的分支。

但是管道在尝试与 master 进行比较时返回错误

+ git log $BITBUCKET_BRANCH --oneline --not master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

请注意管道中的设置步骤(这是由 bitbucket 预先定义的,我无法更改)

git clone --branch="abdullah-s/bitbucketpipelinesyml-created-online-wit-1489917130851" --depth 50 https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/abdullah-s/webook.git $BUILD_DIR;
git reset --hard ac61f080a28428bdd885735374164577a2b0aa43;
git remote set-url origin git@bitbucket.org:abdullah-s/webook.git

在设置的第一个命令中,bitbucket 仅从我的存储库中克隆了一个分支

我试过的

我试过拉高手

- git checkout -b master
- git pull origin master
- git log $BITBUCKET_BRANCH --oneline --not master

但出现错误

+ git pull origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

问题

如何比较 bitbucket 管道中的两个分支?

我没有你问题的完整答案,只是一个提示:你可以通过将密码存储为 SECRET 环境变量来绕过权限问题,然后在拉取时将管道标识为你自己。

https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html

正如您正确指出的那样,Bitbucket 管道只会克隆触发构建的特定分支。

因此,RefSpec 将被设置为特定分支,您将无法合并或区分其他分支。

例如,如果构建是在 develop 分支上触发的,那么将设​​置以下 refspec:

[remote "origin"]
    url = git@bitbucket.org:xxxxxx
    fetch = +refs/heads/develop:refs/remotes/origin/develop
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

如果您查看可用分支,您会看到:

+ git branch -a
* develop
  remotes/origin/develop

您可以执行以下命令:

git fetch origin "+refs/heads/*:refs/remotes/origin/*"

拉入所有其他分支/标签

From bitbucket.org:xxxx/xxxxx
 * [new branch]      master     -> origin/master
 * [new branch]      release    -> origin/release
 * [new tag]         xxxx -> xxxx