Home > database >  Git/ Azure Devops Pipeline Issues
Git/ Azure Devops Pipeline Issues

Time:11-05

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 readme.md file push it back into the test1 branch so that when the pull request is approved i'll also have the latest readme.md documentation.

but I'm facing the following issues :

On branch refs/heads/callerid
nothing to commit, working tree clean
To https://dev.azure.com/repository
 ! [rejected]        refs/heads/callerid -> refs/heads/callerid (fetch first)
error: failed to push some refs to 'https://dev.azure.com/repository'
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 readme.md and in this pipeline then the approval of the pr would merge it into main branch

CodePudding user response:

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: https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml

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:

   steps:
  - checkout: self
    fetchDepth: 1
    persistCredentials: True
  - task: PowerShell@2
    displayName: PowerShell Script
    inputs:
      targetType: inline
      script:
       git config --global user.email "**@**.com"
       git config --global user.name "**"
       git checkout -b test1
       Add-content -Path $(System.DefaultWorkingDirectory)/README.md -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.

  • Related