2

I'm trying to do a checkout using git from a powershell script using Azure Pipelines (yaml).

When I run the following during my build, my build hangs..

- task: PowerShell@2
    # ------------------------------------------------------
    displayName: Update readme.txt
    # ------------------------------------------------------
    inputs:
      targetType: filePath
      filePath: '$(System.DefaultWorkingDirectory)\${{ parameters.devOpsArtifactName }}\update-changelog.ps1'
      workingDirectory: '$(System.DefaultWorkingDirectory)\${{ parameters.devOpsArtifactName }}'
      arguments: '-WorkingDirectory "$(System.DefaultWorkingDirectory)" -Version "$(buildNumber)" -BranchesToPush "develop" -GitRequestedForEmail "$(Build.QueuedById)" -GitRequestedFor "$(Build.QueuedBy)" -UpdateRepo'
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
function Checkout([String]$branch, [String]$gitRequestedForEmail, [String]$gitRequestedFor)
{
    Write-Host "Checking out $branch for $gitRequestedFor ($gitRequestedForEmail)."

    git config --global credential.modalPrompt false
    git config --global user.email $gitRequestedForEmail
    git config --global user.name $gitRequestedFor

    git fetch
    git checkout $branch
}

EDIT
Supressing the modal (as suggested) doesn't work, preferably I want to use SYSTEM_ACCESSTOKEN to authenticate.

5
  • Not sure, but I suppose you may have a modal dialog prompt from the Git Credential manager. You can suppress this by adding: git config --global credential.modalPrompt false Commented Jan 28, 2019 at 15:05
  • Optionally disabling all interactive prompts in Git by adding set GIT_TERMINAL_PROMPT=0 Commented Jan 28, 2019 at 15:06
  • 2
    Why can't you specify the branch in the YAML or in the parameters when queuing the build? Commented Jan 28, 2019 at 15:15
  • 1
    Try to put the username & password in the fetch command: git fetch https://username:[email protected]/my/repository Commented Jan 28, 2019 at 19:45
  • Thanks, I'll try that tomorrow and see what works.. I need to checkout, update changelog and push to PR source branch and develop. Commented Jan 28, 2019 at 20:10

1 Answer 1

2

Tested using this (inline) script and got it working:

$url = "$(Build.Repository.Uri)".Replace("https://", "")
$url = "https://$env:SYSTEM_ACCESSTOKEN@$url"

Write-Host "Checking out $branch from $url for $gitRequestedFor ($gitRequestedForEmail)."

git fetch $url
git checkout develop
git log --oneline
Sign up to request clarification or add additional context in comments.

2 Comments

Can you please provide your full YAML? I'm struggling with inline scripts
you can use powershell: for inline scripts, learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.