Your question is a little confusing, because the line in the text is exactly the same as the line in your code. But I think you must mean that it fails if you don't `def i`.
Yes, if you don't declare the variable, then it will be in something similar to a global scope for this purpose. I think it actually is called a binding variable and gets scoped to the 'script' level, but I don't quite understand how the pipeline script relates back to straight groovy. So for your purposes, yes, it is global if you don't declare the variable. It is the same with your `previous` variable. If that wasn't declared, it would not work like you expect.