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

Evaluation/references of variables in Scripted Pipeline

XMLWordPrintable

      Consider the following Scripted Pipeline:

      def axisPlatform = [
          "native", 
          "cross", 
      ]
      
      def axisBuildType = [
          "RelWithDebInfo",
          "Debug"
      ]
      
      tasks = [:]
      
      // build packages
      axisPlatform.unique().each { level ->
          axisBuildType.each { buildType ->
              platform = "${level}-${buildType}"
      
              // build package
              tasks["package-${platform}"] = {
                  node("server2") {
                      println level
                      println buildType
                      println platform
                  }
              }
          }
      }
      
      stage("1") {
          parallel tasks
      }
      

      I'm getting:

      [package-native-RelWithDebInfo] native
      [package-native-RelWithDebInfo] RelWithDebInfo
      [package-native-RelWithDebInfo] cross-Debug
      
      [package-native-Debug] native
      [package-native-Debug] Debug
      [package-native-Debug] cross-Debug
      
      [package-cross-RelWithDebInfo] cross
      [package-cross-RelWithDebInfo] RelWithDebInfo
      [package-cross-RelWithDebInfo] cross-Debug
      
      [package-cross-Debug] cross
      [package-cross-Debug] Debug
      [package-cross-Debug] cross-Debug
      

      It seems that the iterator-variables are copied by value, but the platform-variable is taken by reference.

      Is this the expected behavior?

            Unassigned Unassigned
            pboettch Patrick Boettcher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: