Git/ Azure Devops Pipeline Issues


I’m trying to create a pipeline in AzureDevops that will run when creating a pull request.
example :
main branch
test1 branch

When I’m creating a pull request to merge the test1 branch into the main branch my pipeline runs should update automatically the file push it back into the test1 branch so that when the pull request is approved i’ll also have the latest documentation.

but I’m facing the following issues :

On branch refs/heads/callerid
nothing to commit, working tree clean
 ! [rejected]        refs/heads/callerid -> refs/heads/callerid (fetch first)
error: failed to push some refs to ''
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
          git config --global init.defaultbranch $(system.pullRequest.sourceBranch)
          git add .
          git commit -m "deployment $(Build.BuildNumber) [skip ci]"
          git push --set-upstream origin $(system.pullRequest.sourceBranch)

is there anything I should change here? basically here’s where I have the issue.

Removed the actuall link from the repository.

I’d like to have a clean branch name without that refs/heads.
in the scenario above the pull request created to merge callerid branch into main branch. and the caller id should have the latest update on the and in this pipeline then the approval of the pr would merge it into main branch


Please ensure you have set ‘contribute’ permission for the project collection build service(org name){the identity one} as Allow. And if you use yaml, add a checkout section with persistCredentials set to true.
You could see the doc for more details:

Then I could reproduce your question. And I set ‘Force push’ permission for the project collection build service(org name){the identity one} as Allow, it works well on my side.
This is the code:

  - checkout: self
    fetchDepth: 1
    persistCredentials: True
  - task: [email protected]
    displayName: PowerShell Script
      targetType: inline
       git config --global "**@**.com"
       git config --global "**"
       git checkout -b test1
       Add-content -Path $(System.DefaultWorkingDirectory)/ -Value "'nss"(you could add the content you want after 'n')
       git add .
       git commit -m "**"
       git branch --set-upstream-to=origin/test1 test1
       git pull
       git push --set-upstream origin test1 --force
      displayName: 'PowerShell Script'

Please kindly see whether it works on your side. Thanks.

Answered By – Antonia Wu-MSFT

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published