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

时间:2017-03-19 11:28:14

标签: git bitbucket

背景

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

即。 fade

问题

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

这是我的yaml管道配置:

add readme /spend 5m

$ BITBUCKET_BRANCH是管道正在运作的分支。

但是在尝试与主

进行比较时,管道返回错误
pipelines:
  default:
    - step:
        script:
          - git log $BITBUCKET_BRANCH --oneline --not master

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

+ 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只从我的repo克隆一个分支

我尝试了什么

我试图拉主人

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

但收到错误

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

问题

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

2 个答案:

答案 0 :(得分:2)

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

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

例如,如果在开发分支上触发了构建,那么将设​​置以下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

答案 1 :(得分:0)

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

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