如何使用 powershell 脚本任务从 GitHub 调用 bamboo 分支而不是 master

How to call a bamboo branch instead of master from GitHub using the powershell script task

我目前正在获取一个名为 Devops 的 GitHub 项目的存储库,它正在获取母版。但是现在我想获取分支而不是默认获取的主分支,但我不知道如何从 powershell 脚本中执行此操作。这就是 master 分支的处理方式。

cd ${bamboo.build.working.directory}
if [ -d devops ] ; then
cd devops 2>/dev/null && git pull || git clone https://MYGIT:myGIT@github.com/myRepo/devops
else
git clone https://MYGIT:myGIT@github.com/myRepo/devops
fi

我试图在它的末尾添加.branchname、/branchname、-branchname 等但它没有找到分支,我如何找到分支而不是主分支?

我通过这样做得到了答案:

git clone -b BRANCH_NAME https://MYGIT:myGIT@github.com/myRepo/devops

对于 else 部分,然后在 if 语句中我这样做了:

# Get the current branch
function gitBranchName {
    $currentBranch = "master"
    git branch | foreach {
        if ($_ -match "<branch_name>") {
            $currentBranch = "<branch_name>"
        }
    }
    return $currentBranch
}