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

Variable assignment in if condition is not working as expected

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: workflow-cps-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.89.3
      Pipeline 2.5
    • Similar Issues:

      Description

      The below code works as expected as a standalone Groovy script (the if condition doesn't enter and so script value remains the same:

      def script = '''mvn -q -Dexec.executable=echo -Dexec.args=\\${project.version} --non-recursive exec:exec'''
      def index
      if ((index = script.indexOf('release:prepare')) != -1) {
          script = script[0..<index-1] + ' -DpushChanges=false ' + script[index..-1]
      }
      

      But the exact same code in a custom vars function misbehaves. The if condition enters anyway with an index value of -1 resulting in a script value of mvn -q -Dexec.executable=echo -Dexec.args=\${project.version} --non-recursive exec:ex -DpushChanges=false c

      If I pull the assignment out of the if condition, it works as expected:

      def index = script.indexOf('release:prepare')
      if (index != -1) {
      

        Attachments

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Unassigned
              Reporter:
              haridsv Hari Dara
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: