Search code examples
azure-pipelinesazure-pipelines-yamlazure-git-deploymentazure-releases

Azure Pipelines: push was rejected because one or more commits contain author email '' which does not match the policy-specified patterns


Azure Pipeline:
I'm running into an issue while trying to build and release microservices using the Maven commands mvn release:prepare release:perform. The pipeline throws the following error:

error: remote unpack failed: error VS403702: The push was rejected because one or more commits contain author email '' which does not match the policy-specified patterns.

It seems that the push is being rejected due to a commit with an empty author email, which doesn't conform to the organization's policy for commit emails.

It's for the user {{your project name}} Build Service ({your organization}), which comes with empty email address.

Result of git log --pretty=format:"%h %an <%ae>" | grep '<>' :

0fc26c311 {{your project name}} Build Service ({your organization}) <>

Also, I already have some valid emails specified for Repository Policies/Commit author email validation.

Updates on 16/07/2024:

Error:

Caused by: org.apache.maven.shared.release.scm.ReleaseScmCommandException: Unable to commit files
Provider message:
The git-push command failed.
Command output:
error: remote unpack failed: error VS403702: The push was rejected because one or more commits contain author email '' which does not match the policy-specified patterns. 
To https://dev.azure.com/URL
 ! [remote rejected]     feature/23972-Pipeline-To-Release -> feature/23972-Pipeline-To-Release (VS403702: The push was rejected because one or more commits contain author email '' which does not match the policy-specified patterns. )
error: failed to push some refs to 'https://dev.azure.com/URL'

    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin (AbstractScmCommitPhase.java:165)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.performCheckins (AbstractScmCommitPhase.java:145)

Script:

Please find the script:

parameters:
  - name: 'skipRelease'
    type: boolean
    default: false    
stages:
  - stage: ValidateGitCheckin
    jobs:
      - job: Validate
        steps:
          - script: |
              git config --add safe.directory $(Build.SourcesDirectory)
              
              if [ "${{ parameters.skipRelease }}" = "true" ]; then
                echo "SKIP_RELEASE: Inherit parameter"
                echo "##vso[task.setvariable variable=skipRelease;isoutput=true]true"
              fi
            displayName: "Validate git checkin"

  - stage: SetupMaven
    jobs:
      - job: DownloadMaven
        steps:
          - task: DownloadSecureFile@1 
            name: settingsxml
            inputs:
              secureFile: "settings.xml"
          - script: |
              mkdir -p $(System.DefaultWorkingDirectory)/.m2
              cp $(settingsxml.secureFilePath) $(System.DefaultWorkingDirectory)/.m2/settings.xml
            displayName: "Setup Maven settings.xml"
            
          - task: PublishPipelineArtifact@1
            inputs:
              path: $(System.DefaultWorkingDirectory)/.m2
              artifact: m2
            displayName: "Download and store Maven settings.xml to artifact"


  - stage: Release
    jobs:
      - job: ReleaseJob
        container: dockerContainer
        steps:
          - checkout: self
            fetchDepth: 0
            persistCredentials: true
          - script: |       
              git config --local user.email "$(build.RequestedForEmail)"
              git config --local user.name "$(build.RequestedFor)"
              git status
              if ! git diff-index --quiet HEAD --; then
              echo "There are uncommitted changes"
              exit 1
              fi
              git checkout feature/$(Build.SourceBranchName)
              git push origin feature/$(Build.SourceBranchName)
            displayName: 'Added git identity'
          - task: DownloadPipelineArtifact@2
            inputs:
              artifact: m2
              path: $(System.DefaultWorkingDirectory)/.m2
          - task: Maven@3
            displayName: 'Release clean'
            inputs:
              mavenPomFile: '$(System.DefaultWorkingDirectory)/pom.xml'
              options: '-B -X -s $(System.DefaultWorkingDirectory)/.m2/settings.xml'    
              goals: 'release:clean'
          - task: Maven@3
            displayName: 'Release prepare'
            inputs:
              mavenPomFile: '$(System.DefaultWorkingDirectory)/pom.xml'
              options: '-B -X -s $(System.DefaultWorkingDirectory)/.m2/settings.xml'    
              goals: 'release:prepare'
          - task: Maven@3
            displayName: 'Release perform'
            inputs:
              mavenPomFile: '$(System.DefaultWorkingDirectory)/pom.xml'
              options: '-B -X -s $(System.DefaultWorkingDirectory)/.m2/settings.xml'    
              goals: 'release:perform'

Solution

  • The 'mvn release:prepare' command will update the POM file and then push it with a new commit to the source repository in Azure Repos.

    If you have enabled "Commit author email validation" option and set the patterns on the Repository Policies, when pushing new commit, it will check whether the email address of the commit author can match the patterns. If not match, it will return the this error.

    enter image description here

    When trying to commit and push new changes to Azure Repos from Azure Pipelines, the task will use the build service account by default. To avoid the issue in pipelines, before running the "mvn release:prepare" command, you can try to run the "git config" command to set a commit author that can match patterns set on the Repository Policies.

    steps:
    . . .
    
    - bash: |
       git config --global user.name "User01"
       git config --global user.email [email protected]
      displayName: 'Set Commit Author'
    
    . . .
    

    With this method, when the subsequent steps to commit new changes, they will use the Commit Author set by above step.