Search code examples
gitazure-devops

fatal: could not read Password for 'https://[email protected]/org/Project/_git/Repo': terminal prompts disabled


Within DevOps, trying to push content to an existing git repository, can be done through general git commands:

git init
git config --global user.email "[email protected]"
git config --global user.name "DevOps Upload"
git remote add devops https://[email protected]/org/Project/_git/$Repo
git add -A
git commit -m "Terraform Scaffolding"
git push -u devops --all 

However, to do so, one needs to pass in authentication:

steps:
 - checkout: self
   persistCredentials: true

What is confusing is that the pipeline appears to be ignoring the persistCredentials parameter:

fatal: Cannot prompt because user interactivity has been disabled.
fatal: could not read Password for 'https://[email protected]/org/Project/_git/Repo': terminal prompts disabled

There is a solution to this git problem here, however, it references an outdated version of DevOps and doesn't seem to be functioning in the same manor today. I've set all Build Service permissions and even tried to pass in the $System_AccessToken for the git remote, but nothing appears to be pushing credentials to the pipeline agemt.

Any assistance with today on why this process doesn't seem to be working would be helpful.


Solution

  • To push commits via pipeline, you may use the two methods below.

    steps:
      - checkout: self
        persistCredentials: true
    
      - bash: |
          echo $(Build.BuildId) >> NewFile-$(Build.BuildId).txt
        displayName: Create a new file to be pushed by pipeline
        
      - bash: |
          git checkout -b $(Build.SourceBranchName)
    
          git config --global user.email "$(Build.RequestedForEmail)"
          git config --global user.name "Pipeline-$(Build.DefinitionName)"
    
          git add .
    
          git commit -m "Push commits by pipeline $(Build.DefinitionName) in build $(Build.RequestedForEmail)"
          
          git push origin $(Build.SourceBranchName)
        displayName: Push commits to source repo (self)
    
    steps:
      - checkout: self
    
      - bash: |
          echo $(Build.BuildId) >> NewFile-$(Build.BuildId).txt
        displayName: Create a new file to be pushed by pipeline
        
      - bash: |
          git checkout -b $(Build.SourceBranchName)
          git remote set-url origin https://$(System.AccessToken)@dev.azure.com/$(AzureDevOpsOrgName)/$(TheProjectName)/_git/$(TheRepoName)
    
          git config --global user.email "$(Build.RequestedForEmail)"
          git config --global user.name "Pipeline-$(Build.DefinitionName)"
    
          git add .
          
          git commit -m "Push commits by pipeline $(Build.DefinitionName) in build $(Build.RequestedForEmail)"
          
          git push origin $(Build.SourceBranchName)
        displayName: Push commits to source repo (self)