SonarQube Jenkins
  1. SonarQube Jenkins
  2. SONARJNKNS-79

"Skip if environment variable is defined" doesn't work for environment variable

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Labels:
      None
    • Environment:
      Jenkins 1.466
      Jenkins Sonar Plugin 1.8
    • Number of attachments :
      0

      Description

      As reported at http://sonar.15.n6.nabble.com/sonar-dev-Jenkins-Plugin-V1-8-Issue-Environment-Variable-Skip-Sonar-Trigger-td4943409.html it seems the skip only works for variables defined as build parameters but not for environment variables.

      We're using the Sonar Jenkins plugin (V1.8 on Jenkins 1.462), and would like to skip Sonar when performing a maven release using the "Skip if environment variable is defined" mechanism.

      To do so a variable called "IS_M2RELEASEBUILD" is defined in "Release environment variable" for the sonar configuration and we use that same variable name in the job config within the Sonar advanced field "Skip if environment variable is defined". Even though we're setting the variables Sonar is still being run even when creating a release.

      For info, we've used a pre-build shell task with an echo of the IS_M2RELEASEBUILD variable, as well as a post-build shell task; both print "true" for the variable value when doing a release. This behaviour has been observed on both Solaris and Win 7 Jenkins environments.

      I experienced the same issue. Are we using it the wrong way? Is there a workaround?

      Thanks,
      Giacomo Boccardo

        Issue Links

          Activity

          Hide
          Jose Sa added a comment -

          What I meant is that it is possible to run Sonar in job in 2 places. As a Build step named "Invoke Standalone Sonar Analysis" and as a post-build action named just "Sonar".

          You can find attached a sample job definition that has both and the workaround for the build step using "Conditional Build Step" plugin to check the build parameter and skip the sonar execution if the parameter "SKIP_SONAR" is set to true.

          For this to work, either case should no run if the parameter was set to true, but just using the build step without the Conditional additional check runs it either way.

          test_sonar.xml job definition: http://pastebin.com/uXRVFkXc
          test_sonar execution output: http://pastebin.com/j6w4WeVF

          Show
          Jose Sa added a comment - What I meant is that it is possible to run Sonar in job in 2 places. As a Build step named "Invoke Standalone Sonar Analysis" and as a post-build action named just "Sonar". You can find attached a sample job definition that has both and the workaround for the build step using "Conditional Build Step" plugin to check the build parameter and skip the sonar execution if the parameter "SKIP_SONAR" is set to true. For this to work, either case should no run if the parameter was set to true, but just using the build step without the Conditional additional check runs it either way. test_sonar.xml job definition: http://pastebin.com/uXRVFkXc test_sonar execution output: http://pastebin.com/j6w4WeVF
          Hide
          Jose Sa added a comment -

          The "Invoke Standalone Sonar Analysis" uses Sonar runner 1.2 (when do you upgrade to 2.0?) while the post-build action "Sonar" uses only Maven method.

          Show
          Jose Sa added a comment - The "Invoke Standalone Sonar Analysis" uses Sonar runner 1.2 (when do you upgrade to 2.0?) while the post-build action "Sonar" uses only Maven method.
          Hide
          Julien HENRY added a comment -

          Could you please use the sonar user mailing list for this kind of question.

          It seems you encounter an issue with Conditional Build Step that at first seems not related to Jenkins Sonar plugin (as I said standalone sonar analysis build step has no built-in skip feature).

          Show
          Julien HENRY added a comment - Could you please use the sonar user mailing list for this kind of question. It seems you encounter an issue with Conditional Build Step that at first seems not related to Jenkins Sonar plugin (as I said standalone sonar analysis build step has no built-in skip feature).
          Hide
          Jose Sa added a comment -

          I would send it to mailing list if I knew what it was and I don't see any mentioned in http://docs.codehaus.org/display/SONAR/Hudson+and+Jenkins+Plugin. care to provide that info ?

          I think this is a lack of consistency issue. When you have in Jenkins System Configuration the options specific for this plugin the possibility to like indicated in the title of this issue to "Skip if environment variable is defined", I would expect that all possible executions of this plugin would behave consistently in the same manner, which is to skip the build if the environment variable "SKIP_SONAR" being defined as a Boolean parameter in the job itself is set to true. Since it has no indication in its documentation this only works with the pos-build step "Sonar" specific only to maven I assumed it was also applicable to the Standalone build step.

          Regarding Conditional Build Step plugin, there is no issue with. That is actually the Workaround I found that overcomes this Problem on the Standalone Sonar Analysis build step because it was not behaving as expected. In my opinion the use of this plugin would not be needed if the Plugin had consistent behavior.

          The test_sonar.xml I've indicated above is an example of such, just copy it to your instance, run it and you'll see the problem.

          Show
          Jose Sa added a comment - I would send it to mailing list if I knew what it was and I don't see any mentioned in http://docs.codehaus.org/display/SONAR/Hudson+and+Jenkins+Plugin . care to provide that info ? I think this is a lack of consistency issue. When you have in Jenkins System Configuration the options specific for this plugin the possibility to like indicated in the title of this issue to "Skip if environment variable is defined", I would expect that all possible executions of this plugin would behave consistently in the same manner, which is to skip the build if the environment variable "SKIP_SONAR" being defined as a Boolean parameter in the job itself is set to true. Since it has no indication in its documentation this only works with the pos-build step "Sonar" specific only to maven I assumed it was also applicable to the Standalone build step. Regarding Conditional Build Step plugin, there is no issue with. That is actually the Workaround I found that overcomes this Problem on the Standalone Sonar Analysis build step because it was not behaving as expected. In my opinion the use of this plugin would not be needed if the Plugin had consistent behavior. The test_sonar.xml I've indicated above is an example of such, just copy it to your instance, run it and you'll see the problem.
          Hide
          Julien HENRY added a comment -

          It is the expected behavior that the sonar build step is not skipped since the "Skip if environment..." parameter only applies to the post job Sonar action (we tried to make it more clear in SONARPLUGINS-1719). We will not implement a skip mechanism for the build step especially because as you said there is an existing plugin to do the same in a consistent way for all kind of build steps.
          If you disagree with this point of view feel free to open a discussion on user mailing list (http://docs.codehaus.org/display/SONAR/Mailing-lists).

          Concerning the update to Sonar Runner 2.0 this was addressed by SONARPLUGINS-2126. The vote has been started on the dev mailing list (http://sonar.15.n6.nabble.com/sonar-dev-VOTE-Jenkins-Hudson-Sonar-Plugin-2-0-td5004051.html).

          Show
          Julien HENRY added a comment - It is the expected behavior that the sonar build step is not skipped since the "Skip if environment..." parameter only applies to the post job Sonar action (we tried to make it more clear in SONARPLUGINS-1719 ). We will not implement a skip mechanism for the build step especially because as you said there is an existing plugin to do the same in a consistent way for all kind of build steps. If you disagree with this point of view feel free to open a discussion on user mailing list ( http://docs.codehaus.org/display/SONAR/Mailing-lists ). Concerning the update to Sonar Runner 2.0 this was addressed by SONARPLUGINS-2126 . The vote has been started on the dev mailing list ( http://sonar.15.n6.nabble.com/sonar-dev-VOTE-Jenkins-Hudson-Sonar-Plugin-2-0-td5004051.html ).

            People

            • Assignee:
              Julien HENRY
              Reporter:
              Giacomo Boccardo
            • Votes:
              5 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: