0

I'm trying to write a script that will merge changes from the master to my branch that will be built in Azure DevOps

git config –global user.email "My Email"
git config –global user.name "My User Name"
REPO="$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_git/$(Build.Repository.Name)"
EXTRAHEADER="Authorization: Bearer $env:SYSTEM_ACCESSTOKEN"
git -c http.extraheader="$EXTRAHEADER" clone $REPO
cd $(Build.Repository.Name)
# ls


git config http.$REPO.extraHeader "$EXTRAHEADER"
              
git checkout $(Build.SourceBranchName)
git status
ls -la
git merge --no-ff --no-edit origin/automatecitest
ls -la

I have configured the rights that are described in this article. but I am getting errors

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <vsts@fv.fx.internal.cloudapp.net>) not allowed

Could you please help me. Thanks.

Francisco Puga
  • 23,869
  • 5
  • 48
  • 64
  • Have you tried doing exactly what the error message suggests, i.e., telling Git what author and committer name and email address to use for new commits? In general, though, it's unwise to completely automate merging, because some merges *fail*. – torek Aug 25 '21 at 21:20
  • 1
    @torek "*…telling Git what author and committer name and email address to use…*" The first two lines of the script; wrong kind of dash there. – phd Aug 25 '21 at 21:58
  • @phd: oops, I skimmed right over those somehow (probably because the OP didn't show any error output from those two commands, even though they do produce errors). And yes, the text in the question has en-dashes instead of double hyphens. – torek Aug 25 '21 at 22:43

1 Answers1

0

Based on your actual script, you are merging origin/automatecitest to main.

I archive via below code:

trigger: none

pool:
  vmImage: Ubuntu-latest

steps:
- checkout: none

- script: |
    REPO="$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_git/$(Build.Repository.Name)"
    git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" $REPO
    cd $(Build.Repository.Name)
    ls
    git config user.email "tester1@hotmail.com"
    git config user.name "tester1"
    git merge --no-ff --no-edit origin/automatecitest
    ls -la

I enabled in project setting: enter image description here

enter image description here

Note:

  1. You can change the branch, from main to other..
  2. The change will not push back to main branch since you need to add extra step to push. if you cat file change afte merge in the task, you can see the merge result.
wade zhou - MSFT
  • 1,397
  • 1
  • 3
  • 6
  • thanks for your answer, I merge my branch but I can't make a push command I added - checkout: self persistCredentials: true ``` echo GIT PUSH git push https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/organization/project/_git/repo $(Build.SourceBranchName)``` error GIT PUSH fatal: Authentication failed for 'https://dev.azure.com/organization/project/_git/repo $(Build.SourceBranchName)```' https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml assigned the rights as in the article – Vitalii Fedorenko Aug 27 '21 at 07:34
  • you have used 'persistCredentials: true', then you can directly push the code, no need to use system.accesstoken. Remember to grant repository permission for `Project Collection Build Service (account name)'. Please refer to link for the details: https://stackoverflow.com/questions/56541458/azure-pipeline-doest-allow-to-git-push-throwing-genericcontribute-permission – wade zhou - MSFT Aug 27 '21 at 10:01
  • @VitaliiFedorenko, how is it going? would you please mark my reply as answer if it helps? let me know if you have any queries. Thanks. – wade zhou - MSFT Aug 31 '21 at 06:44
  • Hi @wadezhou, yes, everything worked, thanks so much) – Vitalii Fedorenko Aug 31 '21 at 11:35