Pull Request builds fail with Sonar

I understood that sonar should not be executed in “unsecure” environments (pull requests).
But via .travis.yml the sonar execution cannot be omitted (and so fails due to missing configuration - localhost:9000).
Here my try
language: java

# https://docs.travis-ci.com/user/sonarcloud/
addons:
  sonarcloud:
    organization: "quaddy-services-github" # the key of the org you chose at step #3
    
    # see SONAR_TOKEN property in https://travis-ci.org/quaddy-services/escape-from-intranet/settings
    # token:
    #   secure: "*********" # encrypted value of your token
    
script:
  # https://community.sonarsource.com/t/travis-plugin-is-failing-on-external-pull-request/807/8
  # https://docs.travis-ci.com/user/pull-requests#double-builds-on-pull-requests
  # the following command line builds the project, runs the tests with coverage and then execute the SonarCloud analysis
  - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
  - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar'
  - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then mvn clean install'  

but failed:
https://travis-ci.org/quaddy-services/escape-from-intranet/builds/535725340?utm_source=github_status&utm_medium=notification

as addon already performed
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar

Sorry for confusion.
I did not see the line I forgot to remove.
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar

Now sonar is no longer performing (but I have some failure in the script)…
https://travis-ci.org/quaddy-services/escape-from-intranet/builds/535730695?utm_source=github_status&utm_medium=notification

So nothing to do here!

Final working script section is:

script:
  - echo "TRAVIS_SECURE_ENV_VARS=${TRAVIS_SECURE_ENV_VARS}";
  - >
    if [ "${TRAVIS_SECURE_ENV_VARS}" == "true" ]; then
      echo;
      echo "Running sonar build";
      # the following command line builds the project, runs the tests with coverage and then execute the SonarCloud analysis
      mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar;
    fi;
  - >
    if [ "${TRAVIS_SECURE_ENV_VARS}" == "false" ]; then
      echo;
      echo "Running pullrequest build";
      mvn clean install;
    fi;
1 Like

Glad to hear you could figure this one out!

1 Like
Imprint