在Travis-CI构建中,如何仅在主分支上调用SonarQube

时间:2019-03-07 23:11:54

标签: sonarqube travis-ci

由于我在SonarQube.com(SQ)上只有免费的CE帐户,因此我不能让它建立master以外的任何分支机构。 我该如何设置.travis.yml,使其仅在构建master分支时才触发SQ,但仍会构建其他分支(只是不触发SQ)?

1 个答案:

答案 0 :(得分:0)

script中的.travis.yml部分混为一谈对我有用。

重要部分是:

script:
  - cmdExtra=""; if [ $TRAVIS_BRANCH = "master" ]; then cmdExtra="<your-sonar-trigger-here>"; fi; <your-cmd-here> $cmdExtra

这是基于Maven的Java项目的完整示例:

language: java
sudo: false # faster builds

addons:
  sonarcloud:
    organization: "myOrganizationId"
    token:
      secure: "134f51f3451f3451ffe12f3124123123123123123123"

jdk:
  - openjdk8

script:
# NOTE JaCoCo is used to have code coverage, the agent has to be activated
# NOTE The SonarCube Community Edition (free plan) only supports branch "master".
  - cmdExtra=""; if [ $TRAVIS_BRANCH = "master" ]; then cmdExtra="sonar:sonar"; fi; mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package $cmdExtra

cache:
  directories:
    - '$HOME/.m2/repository'
    - '$HOME/.sonar/cache'