Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37400

Symbols for constants variables in workflow-cps

XMLWordPrintable

      I want to use enum names for parameters of steps in pipeline jobs like:

      def runWrapper = selectRun job: 'upstream-project-name', 
        selector: status(Successful) 
      

      Successful is an enum value.
      I believe workflow-cps can determine what Successful means as the type of status is required to be an enum type.

      Background:
      Run selector plugin is working to introduce {{@Symbol}}s: https://github.com/jenkinsci/run-selector-plugin/pull/14
      It allows scripts use run-selector like this:

      def runWrapper = selectRun job: 'upstream-project-name', 
        selector: status('Successful') 
      

      'Successful' will be resolved to BuildStatus.Successful with Enum.valueOf (BuildStatus is an enum type).

      But other selectors in run-selector often expects strings starting with lower-case letters. For example, PermalinkRunSelector expects "lastSuccessful". This causes inconsistencies of usages of selectors and should be confusing for users.
      On the other hands, allowing "successlful" for parameters of status means to define enum values with lower-case letters like BuildStatus.successlful. It is strange as Java code.

      I think this can be resolved by either of following ways:
      A. Allow to use enum names as properties:

      def runWrapper = selectRun job: 'upstream-project-name', 
        selector: status(Successful) 
      
      • Successful will be resolved to BuildStatus.Successful as it's specified as a parameter requiring BuildStatus type, just like status is resolved to StatusRunSelector as it's specified as a parameter requiring RunSelector type.

      B. Allow developers define aliases for enum values like:

      enum BuildStatus {
        @EnumSymbol("successful")
        Successful,
      }
      

      And I believe it makes sense to apply this not only to enum types, but also to enum-like types like hudson.model.Result.

            ikedam ikedam
            ikedam ikedam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: