This is a classic issue that a lot of people run into in various programming 
languages. https://groovyconsole.appspot.com/script/5078409050849280 
<https://groovyconsole.appspot.com/script/5078409050849280> shows the same 
problem and one way to fix it (click "edit in console" and then you can execute 
the script). This kind of issue is why in Java, anonymous classes and lambda 
expressions can only reference variables that are final or effectively final.

> On Apr 16, 2021, at 11:16, spratap singh <spratap2...@gmail.com> wrote:
> 
> registeries = [1,2,3,4] 
>  Map tasks = [:]
>  for (j=0;j<=registeries.size();j++) 
> { 
>  tasks["Code ${j}"] = { -> sh "touch ${j}" }
>  } 
>  parallel(tasks) 
>  sh "ls -lrt"
> 
> Above code should create files 0,1,2,3,4,5
> 
> but the last line ls -lrt only prints 5 which means it is only taking the 
> last iteration value in all values of map tasks
> 
> Can anyone tell what I am doing wrong here ?
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to jenkinsci-users+unsubscr...@googlegroups.com 
> <mailto:jenkinsci-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-users/bfde4364-d93d-4b7a-9ff6-7b2e7bd3c7a2n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-users/bfde4364-d93d-4b7a-9ff6-7b2e7bd3c7a2n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/FABC5220-69E1-449A-AA08-5C0BA770D025%40cloudbees.com.

Reply via email to