A switch expression like this in a groovy DSL pipeline code.

      javaVersion = switch (jdkVersion) {
      case "JDK8", null -> "OpenJDK 8"
      case "JDK11" -> "OpenJDK 11"
      case "JDK17" -> "OpenJDK 17"
      {{default -> { error("The JDK version ${jdkVersion} is unknown. Expected JDK8 (default), JDK11 or JDK17."); "" }}}
      }

      produces a compile error similar to this.
      WorkflowScript: 96: unexpected token: switch @ line 96, column 29.

       

      Jenkins 2.375.1

          [JENKINS-70831] switch expression compile error

          Jenkins 2.375.1 uses Groovy 2.4.21. Groovy 2.4.21 documentation for switch does not mention any -> syntax. Groovy 4.0.0 documentation for switch does describe switch expressions.

          I think this is a duplicate of JENKINS-68690, which requests upgrading to Groovy 4.0.x.

          Kalle Niemitalo added a comment - Jenkins 2.375.1 uses Groovy 2.4.21 . Groovy 2.4.21 documentation for switch does not mention any -> syntax. Groovy 4.0.0 documentation for switch does describe switch expressions. I think this is a duplicate of JENKINS-68690 , which requests upgrading to Groovy 4.0.x.

          Jacek added a comment -

          Very sad, but correct. Sorry for a duplicate, please upgrade.

          Jacek added a comment - Very sad, but correct. Sorry for a duplicate, please upgrade.

            Unassigned Unassigned
            gajatko Jacek
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: