Pipeline builds have the annoying habit of sandboxing themselves, which means that they watch for "dangerous" commands. If your pipeline groovy script has a dangerous command (which can be a whole hell of a lot of things), it will not let you execute the command and fail the script.
If your sandbox is enabled, you need to approve of all dangerous executions, on the page found under: Manage Jenkins > In-process Script Approval
Or you could turn off the sandbox. Which is a funky and annoying guardian, that makes testing a script a devil of a thing.