1

I am making changes to a file in my repository from the Azure DevOps pipeline. I am able to add and commit these changes however, I am having an issue running the git push command. I am working in a branch called develop where all my files are in the root directory.

azure-pipelines.yml

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
        git config --global user.email "user@email.com"
        git config --global user.name "User Name"
        git add .
        git commit -m "Updated README"
        git push origin HEAD:develop

This gives me the error: [detached HEAD d646d26] Updated README 1 file changed, 3 insertions(+), 3 deletions(-) fatal: could not read Password for 'https://@dev.azure.com': terminal prompts disabled ##[error]PowerShell exited with code '1'.

Is this a permission issue, or am I pushing to the develop branch incorrectly? Also, is there a better/easier way to do this?

agw2021
  • 107
  • 7
  • 1
    Does this answer your question? [Fatal: Could not read password for 'https://OrganizationName@dev.azure.com': terminal prompts disabled](https://stackoverflow.com/questions/56733922/fatal-could-not-read-password-for-https-organizationnamedev-azure-com-ter) – JCH Jul 22 '21 at 19:53
  • Can you show your whole pipeline? – Krzysztof Madej Jul 23 '21 at 13:17
  • git push uses PAT token to authenticate, which is not there when you run it from another pipeline. So you need `git push https://{PAT}@dev.azure.com/{organization}/{project}/_git/{repo-name}` – Hardoman Sep 23 '21 at 11:50

1 Answers1

0

I think it is because you need to persist your credentials, I did it like this, but this will depend on the branches you need to manage:

stages:
- stage: create_file
  jobs:
  - job: copy_vm_template
    steps:
    - checkout: self  
      persistCredentials: true
    - script: |
        git checkout -b main
        echo Creating directory

        mkdir ./linuxvm/$(echo ${{parameters.vm_name}})
        echo Creating vm file

        cp ./linuxvm/template/vm.tf ./linuxvm/$(echo ${{parameters.vm_name}})/$(echo ${{parameters.vm_name}}).tf

        git config --global user.email "your_mail@test.com"
        git config --global user.name "your_user"
        git status
        git add linuxvm/$(echo ${{parameters.vm_name}})
        git commit -m "Your message"
        git push origin main
Caro
  • 19
  • 3