From: Jessica Wagantall Date: Fri, 25 Jun 2021 19:32:25 +0000 (-0700) Subject: Feat: Allow scans in short lived branches X-Git-Tag: v0.66.0^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=dfc4b07132cce65541bc8f2bf1e3bd4920a4ef90;p=releng%2Fglobal-jjb.git Feat: Allow scans in short lived branches Add functionality to allow scans of short lived branches in SonarCloud. Developers will be able to turn this feature on by setting "scan-dev-branch: true" Issue: RELENG-3937 Signed-off-by: Jessica Wagantall Change-Id: I6b32771ba00e86927ba179596c467b37c831bd2d --- diff --git a/.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml b/.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml index c3239a28..5d73a168 100644 --- a/.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml +++ b/.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml @@ -13,6 +13,7 @@ sonarcloud-project-key: KEY sonarcloud-project-organization: ORGANIZATION sonarcloud-api-token: TOKEN + scan-dev-branch: false - project: name: example-sonarcloud-with-prescan-script @@ -30,3 +31,4 @@ sonarcloud-api-token: TOKEN sonar-prescan-script: | echo "Run script at start of job." + scan-dev-branch: false diff --git a/docs/jjb/lf-maven-jobs.rst b/docs/jjb/lf-maven-jobs.rst index d312cecc..ffbbedc3 100644 --- a/docs/jjb/lf-maven-jobs.rst +++ b/docs/jjb/lf-maven-jobs.rst @@ -515,6 +515,8 @@ multi-branch configuration. (default: 10) :submodule-disable: Disable submodule checkout operation. (default: false) + :scan-dev-branch: Run the scan on a developer branch. + (default: false) :gerrit_sonar_triggers: Override Gerrit Triggers. diff --git a/jjb/lf-maven-jobs.yaml b/jjb/lf-maven-jobs.yaml index 2b5c7944..c63fe819 100644 --- a/jjb/lf-maven-jobs.yaml +++ b/jjb/lf-maven-jobs.yaml @@ -1145,6 +1145,7 @@ submodule-recursive: true submodule-timeout: 10 submodule-disable: false + scan-dev-branch: false gerrit_sonar_triggers: - comment-added-contains-event: @@ -1223,6 +1224,7 @@ sonarcloud-project-organization: "{sonarcloud-project-organization}" sonarcloud-api-token: "{sonarcloud-api-token}" sonarcloud-java-version: "{sonarcloud-java-version}" + scan-dev-branch: "{scan-dev-branch}" # With SonarQube - conditional-step: condition-kind: not @@ -1257,6 +1259,7 @@ sonarcloud-project-organization: "{sonarcloud-project-organization}" sonarcloud-api-token: "{sonarcloud-api-token}" sonarcloud-java-version: "{sonarcloud-java-version}" + scan-dev-branch: "{scan-dev-branch}" # With SonarQube - conditional-step: condition-kind: not @@ -1309,6 +1312,7 @@ MAVEN_GOALS={mvn-goals} API_TOKEN={sonarcloud-api-token} SONARCLOUD_JAVA_VERSION={sonarcloud-java-version} + SCAN_DEV_BRANCH={scan-dev-branch} - lf-provide-maven-settings: global-settings-file: global-settings settings-file: "{mvn-settings}" diff --git a/jjb/lf-python-jobs.yaml b/jjb/lf-python-jobs.yaml index 8d3c8855..6fbd226f 100644 --- a/jjb/lf-python-jobs.yaml +++ b/jjb/lf-python-jobs.yaml @@ -264,6 +264,7 @@ submodule-disable: false tox-dir: "." tox-envs: "" + scan-dev-branch: false gerrit_trigger_file_paths: - compare-type: REG_EXP @@ -336,6 +337,7 @@ sonarcloud-project-organization: "{sonarcloud-project-organization}" sonarcloud-api-token: "{sonarcloud-api-token}" sonarcloud-java-version: "{sonarcloud-java-version}" + scan-dev-branch: "{scan-dev-branch}" # With SonarQube - conditional-step: condition-kind: not diff --git a/releasenotes/notes/sonar-short-lived-branch-support-835d15e843160095.yaml b/releasenotes/notes/sonar-short-lived-branch-support-835d15e843160095.yaml new file mode 100644 index 00000000..d35fdd49 --- /dev/null +++ b/releasenotes/notes/sonar-short-lived-branch-support-835d15e843160095.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add support in lf-maven-sonar scan jobs to process short lived dev branches. diff --git a/shell/maven-sonar.sh b/shell/maven-sonar.sh index 9e00d218..9af6e427 100644 --- a/shell/maven-sonar.sh +++ b/shell/maven-sonar.sh @@ -34,6 +34,16 @@ if [ "$SONAR_HOST_URL" = "https://sonarcloud.io" ]; then params+=("-Dsonar.projectKey=$PROJECT_KEY") params+=("-Dsonar.organization=$PROJECT_ORGANIZATION") params+=("-Dsonar.login=$API_TOKEN") + if $SCAN_DEV_BRANCH; then + echo "Will scan short lived branch ..." + # shellcheck disable=SC2236 + if [ ! -z ${GERRIT_CHANGE_NUMBER+x} ]; then + GERRIT_SHORT_LIVED_BRANCH=${GERRIT_CHANGE_NUMBER}-${GERRIT_PATCHSET_NUMBER} + params+=("-Dsonar.analysis.gerritProjectName=$PROJECT") + params+=("-Dsonar.branch.target=$GERRIT_BRANCH") + params+=("-Dsonar.branch.name=$GERRIT_SHORT_LIVED_BRANCH") + fi + fi fi if [ "$SET_JDK_VERSION" != "$SONARCLOUD_JAVA_VERSION" ]; then