PullRequest Analyze contains not relevant changes

Template for a good new topic, formatted with Markdown:

  • we use Bitbucket Cloud
  • Build are done in GitLab agent
  • It is maven sonar plugin: mvn verify sonar:sonar
  • Java
  • Steps to reproduce: it is not consistent, periodically not relevant changes from master commits leaks to PR analyzes
  • Potential workaround: restart build with analyzes, but it is very uncomfortable. Since you can’t rely on your code test coverage measure.

Hi,

What does your checkout look like? Also, I would expect to see clean in your mvn command. Are you already in a clean workspace?

 
Ann

Hi. sure it is a clean runner from docker image. Checkout is done via GitLab. Also we had no such problem before, it has appear around 1 month ago without any changes from out side. Appears quite often but at same time not always.

I would be checking our CI pipelines, but we see 2 weeks old master changes in recently created PR. So these changes were analyzed in master 2 weeks ago and still pops out in coverage report.

Hi,

Could you share your check command(s)?

 
Ann

Ok, here is pipline from GitLab

Run PR build:
  stage: pr_build
  image: maven:3.8.5-ibm-semeru-17-focal
  variables:
    GIT_DEPTH: 50
    MAVEN_OPTS: "-XX:ActiveProcessorCount=2 -Xmx4G -XX:TieredStopAtLevel=1 -XX:+UseParallelGC"
    SONAR_USER_HOME: "sonar_home"
  cache:
    paths:
      - maven_repo/
      - sonar_home/
  before_script:
    - git config user.name "docker"
    - git config user.email "doсker@st.com"
    - git fetch origin ${BITBUCKET_PR_DESTINATION_BRANCH}
    - git merge origin/${BITBUCKET_PR_DESTINATION_BRANCH}
  script:
  - mvn -B -s settings.xml -P coverage
    -Dmaven.repo.local=maven_repo
    -Dsonar.log.level=WARN
    -Dsonar.pullrequest.branch=${BITBUCKET_BRANCH}
    -Dsonar.pullrequest.base=${BITBUCKET_PR_DESTINATION_BRANCH}
    -Dsonar.pullrequest.key=${BITBUCKET_PR_ID}
    -Dsonar.pullrequest.bitbucketcloud.repository=${BITBUCKET_REPO_UUID}
    -Dsonar.pullrequest.bitbucketcloud.owner=${BITBUCKET_REPO_OWNER_UUID}
    -Dsonar.pullrequest.bitbucketcloud.triggerCommit=${BITBUCKET_COMMIT}
    verify sonar:sonar
  interruptible: true
  artifacts:
    when: always
    reports:
      junit: ./**/target/surefire-reports/TEST-*.xml

all env variables are provided from the bitbucket

Hi,

I see two things here. First

Git depth should be 0

You’re doing a merge commit before analysis. So you’re not giving analysis the PR code, but some hybrid.

Can you correct both of these things and try again?

 
Ann

1 Like

Hi,

I will try to set GIT_DEPTH to 0.

I don’t want to remove “pre-merge” with git merge origin/${BITBUCKET_PR_DESTINATION_BRANCH}

since it provides additional check for merge compatibility with target branch.
It is not really a hybrid it is an update to PR target branch ( in most cases it is just master branch and master changes are already analyzed)

Also it is a default behavior for Bitbucket Pipelines for PRs. So it should be supported.

pull requests 
A special pipeline that only runs on pull requests initiated from within your repository. 
It merges the destination branch into your working branch before it runs.
Pull requests from a forked repository don't trigger the pipeline. If the merge fails, the pipeline stops.

Hi,

Can you verify that none of the “not relevant changes” came from this merge?

 
Ann

Ok. I will validate it. Need some time to check if GIT_DEPTH 0 has fixed the issue

So far GIT_DEPTH 0 looks like a desired fix. We can give it one more week to validate this solution.

Thank you!

Issue is solved, we can close this topic. GIT_DEPTH 0 was enough

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.