# Pull Request builds fail with Sonar

**URL:** <https://travis-ci.community/t/pull-request-builds-fail-with-sonar/3473>\
**Category:** Travis CI Discussions & Feedback\
**Created:** [May 22, 2019, 11:07am UTC](https://travis-ci.community/t/pull-request-builds-fail-with-sonar/3473 "2019-05-22T11:07:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ca-stefan-cordes](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@ca-stefan-cordes](https://travis-ci.community/u/ca-stefan-cordes)\
**Post date:** [May 22, 2019, 11:07am UTC](https://travis-ci.community/t/pull-request-builds-fail-with-sonar/3473/1 "2019-05-22T11:07:21Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ca-stefan-cordes](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@ca-stefan-cordes](https://travis-ci.community/u/ca-stefan-cordes)\
**Post date:** [May 22, 2019, 11:11am UTC](https://travis-ci.community/t/pull-request-builds-fail-with-sonar/3473/2 "2019-05-22T11:11:01Z")

</div>

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](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;
```

---

<div class="post-metadata">

**Author:** ![dominic](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dominic/32/14_2.png) [@dominic](https://travis-ci.community/u/dominic)\
**Post date:** [May 23, 2019, 2:09pm UTC](https://travis-ci.community/t/pull-request-builds-fail-with-sonar/3473/3 "2019-05-23T14:09:52Z")

</div>

Glad to hear you could figure this one out!

---

<div class="post-metadata">

**Author:** ![dominic](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dominic/32/14_2.png) [@dominic](https://travis-ci.community/u/dominic)\
**Post date:** [May 23, 2019, 2:09pm UTC](https://travis-ci.community/t/pull-request-builds-fail-with-sonar/3473/4 "2019-05-23T14:09:55Z")

</div>

Closed on May 23, 2019, 2:09pm UTC


