From b8f2b40a430565e551a13a70a595df1b9203bede Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20OLIVIER?= <cedric3.olivier@orange.com>
Date: Wed, 8 Sep 2021 10:53:24 +0200
Subject: [PATCH] feat: Change boolean variable behaviour
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

BREAKING CHANGE: boolean variable now triggered on explicit 'true' value

Signed-off-by: Cédric OLIVIER <cedric3.olivier@orange.com>
---
 README.md                     | 4 ++--
 templates/gitlab-ci-sonar.yml | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 5bcd5a2..ba58a2c 100644
--- a/README.md
+++ b/README.md
@@ -31,9 +31,9 @@ It is bound to the `test` stage, and uses the following variables:
 | :lock: `SONAR_PASSWORD`  | SonarQube password (depends on your authentication method)             | _none_ |
 | `SONAR_BASE_ARGS`        | SonarQube [analysis arguments](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) | `-Dsonar.host.url=${SONAR_URL} -Dsonar.projectKey=${CI_PROJECT_PATH_SLUG} -Dsonar.projectName=${CI_PROJECT_PATH} -Dsonar.projectBaseDir=. -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues` |
 | :lock: `SONAR_GITLAB_TOKEN` | GitLab [access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) with `api` scope. When set, activates the [Sonar GitLab plugin](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/#plugins-properties) integration. | _none_ |
-| `SONAR_BRANCH_ANALYSIS_DISABLED` | Set to disable automatic [Pull Request Analysis](https://docs.sonarqube.org/latest/analysis/pull-request/) and [Branch Analysis](https://docs.sonarqube.org/latest/branches/overview/)  | _none_ (enabled) |
+| `SONAR_BRANCH_ANALYSIS_DISABLED` | Set to `true` to disable automatic [Pull Request Analysis](https://docs.sonarqube.org/latest/analysis/pull-request/) and [Branch Analysis](https://docs.sonarqube.org/latest/branches/overview/)  | _none_ (enabled) |
 | `SONAR_GITLAB_ARGS`      | Extra arguments to use with [Sonar GitLab plugin](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/#plugins-properties) | `-Dsonar.gitlab.url=${CI_SERVER_URL} -Dsonar.gitlab.user_token=${SONAR_GITLAB_TOKEN} -Dsonar.gitlab.project_id=${CI_PROJECT_ID} -Dsonar.gitlab.commit_sha=${CI_COMMIT_SHA} -Dsonar.gitlab.ref_name=${CI_COMMIT_REF_NAME}` |
-| `SONAR_AUTO_ON_DEV_DISABLED` | When set, SonarQube analysis becomes **manual** on development branches (automatic otherwise) | _none_ |
+| `SONAR_AUTO_ON_DEV_DISABLED` | When set to `true`, SonarQube analysis becomes **manual** on development branches (automatic otherwise) | _none_ |
 
 #### Automatic Branch Analysis & Pull Request Analysis
 
diff --git a/templates/gitlab-ci-sonar.yml b/templates/gitlab-ci-sonar.yml
index bad23a6..4d5d5cf 100644
--- a/templates/gitlab-ci-sonar.yml
+++ b/templates/gitlab-ci-sonar.yml
@@ -119,7 +119,7 @@ stages:
   }
   
   function sonar_autodetect_mr() {
-    if [[ "$SONAR_BRANCH_ANALYSIS_DISABLED" ]]
+    if [[ "$SONAR_BRANCH_ANALYSIS_DISABLED" == "true" ]]
     then
       log_info "Branch Analysis and Merge Request Analysis are disabled"
       return
@@ -278,7 +278,7 @@ stages:
     fi
   }
 
-  if [[ -z "$TEMPLATE_CHECK_UPDATE_DISABLED" ]]; then check_for_update sonar "1.3.2"; fi
+  if [[ "$TEMPLATE_CHECK_UPDATE_DISABLED" != "true" ]]; then check_for_update sonar "1.3.2"; fi
   unscope_variables
 
   # ENDSCRIPT
@@ -316,7 +316,7 @@ sonar:
     # on production or integration: auto
     - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF'
     # else (non-production, non-integration branches): manual if $SONAR_AUTO_ON_DEV_DISABLED
-    - if: $SONAR_AUTO_ON_DEV_DISABLED
+    - if: '$SONAR_AUTO_ON_DEV_DISABLED == "true"'
       when: manual
       allow_failure: true
     # else: auto & allow failure
-- 
GitLab