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