简体   繁体   中英

fatal: remote error: CAPTCHA required - Bitbucket - Powershell Script

I wants to checkout the branch and commit the code changes using powershell script. This powershell script will be called from c# code.

But some times i'm getting the following issue

fatal: remote error: CAPTCHA required Your Bitbucket account has been locked. To unlock it and log in again you must solve a CAPTCHA. This is typically caused by too many attempts to login with an incorrect password. The account lock prevents your SCM client from accessing Bitbucket and its mirrors until it is solved, even if you enter your password correctly.

If i logout in browser and login again by entering the CAPTCHA it is working fine. But if i host my application on server and if issue occurs, Logging out and login again is not the proper fix.

Can you please suggest good approach of handling this issue.

My Powershell code for Cloning the branch:

param(
    [parameter(position=0)]
    [string]$checkoutDirectory,

    [parameter(position=1)]
    [string]$checkoutBranch
)

function CheckoutTheCode($checkoutRepoUrl, $checkoutDirectory, $checkoutBranch)
{
    [hashtable]$Return = @{}
    try
    {
        if(Test-Path -Path $checkoutDirectory )
        {
            Remove-Item -Recurse -Force $checkoutDirectory
        }

        New-Item -ItemType directory -Path $checkoutDirectory

        # Cloning
        git clone --single-branch -b $checkoutBranch $checkoutRepoUrl $checkoutDirectory

        $Return.Branch = $checkoutBranch
        $Return.Directory = $checkoutDirectory
        $Return.Status = $true
        $Return.Message = "Success"
    }
    catch
    {
        $Return.Message = $Error[0].Exception
        $Return.Status = $false
    }

    Return $Return 
}

My Powershell code for Commit changes:

param(
    [parameter(position=0)]
    [string]$checkoutDirectory,

    [parameter(position=1)]
    [string]$commitMessage
)

function CommitTheCode($checkoutDirectory, $commitMessage)
{
    [hashtable]$Return = @{}
    try
    {
        cd $checkoutDirectory
        git add .
        git commit -m $commitMessage
        git push

        $Return.Status = $true
        $Return.Message = "Success"
    }
    catch
    {
        $Return.Message = $Error[0].Exception
        $Return.Status = $false
    }

    Return $Return 
}

CommitTheCode $checkoutDirectory $commitMessage

The following steps worked for me (without asking a Bitbucket admin to click a button)

For Windows,

  1. go to the credential manager (you can find this by searching for it in Start menu)
  2. remove all credentials related to your bitbucket account
  3. try again with your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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