Skip to content

Instantly share code, notes, and snippets.

@aborsu
Last active April 7, 2016 08:53
Show Gist options
  • Save aborsu/09b5887ca37dfcf6044963a4501322a5 to your computer and use it in GitHub Desktop.
Save aborsu/09b5887ca37dfcf6044963a4501322a5 to your computer and use it in GitHub Desktop.
circle-ci
#!/bin/bash
function install() {
wget -N http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip;
unzip -o sonar-runner-dist-2.4.zip;
}
function run() {
if [ $CI_PULL_REQUEST ];
then ./sonar-runner-2.4/bin/sonar-runner \
-Dsonar.host.url=$SONAR_HOST \
-Dsonar.login=$SONAR_LOGIN \
-Dsonar.password=$SONAR_PASSWORD \
-Dsonar.projectKey=$CIRCLE_PROJECT_USERNAME:$CIRCLE_PROJECT_REPONAME \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.github.repository=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME \
-Dsonar.github.pullRequest=${CI_PULL_REQUEST##*/} \
-Dsonar.github.oauth=$SAGA_STALIN_TOKEN \
-Dsonar.analysis.mode=preview;
elif [ "$CIRCLE_BRANCH" == "master" ];
then ./sonar-runner-2.4/bin/sonar-runner \
-Dsonar.host.url=$SONAR_HOST \
-Dsonar.login=$SONAR_LOGIN \
-Dsonar.password=$SONAR_PASSWORD \
-Dsonar.projectKey=$CIRCLE_PROJECT_USERNAME:$CIRCLE_PROJECT_REPONAME \
-Dsonar.sourceEncoding=UTF-8;
fi
}
function check() {
if [ -z $CI_PULL_REQUEST ] && [ "$CIRCLE_BRANCH" != "master" ] && [ "$CIRCLE_BRANCH" != "staging" ];
then
curl -XPOST "https://circleci.com/api/v1/project/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BUILD_NUM}/cancel?token=${CI_API_TOKEN}" > /dev/null;
exit 0;
fi
}
case "$1" in
install)
install
;;
run)
run
;;
check)
check
;;
*)
echo $"Usage: $0 {install|run|check}"
exit 1
esac
@aborsu
Copy link
Author

aborsu commented Apr 7, 2016

Script used to run sonar-runner in circle-ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment