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
  • 266
  • 2
  • 22
  • 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

2 Answers2

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
-1
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
  - master
  - azure-pipelines

pr: none

pool:
  vmImage: "macos-latest"

jobs:
  - job: Perform_Commit_From_CI
    steps:
      - checkout: self
        persistCredentials: true #Important - Persist creds to run further git command
        clean: true
      - task: NodeTool@0
        inputs:
          versionSpec: "16.13.2"
        displayName: "Install Node.js"
      - script: |
          git config --global user.email test@gmail.com
          git config --global user.name "Test User"
        displayName: Configure git
      - script: |
          yarn install
          yarn start NAME_OF_THE_SCRIPT_YOU_WANT_TO_EXECUTE
          git add -A
          git commit -m 'Test commit [skip ci]'
          git push origin HEAD:your-branch-name-here 
        displayName: "Test Script"

This should work without PAT

Kailash Uniyal
  • 878
  • 1
  • 10
  • 14