I'm trying to setup Groovy in jenkins, so that it automatically is installed on an agent when performing jobs on it.
This is my global configuration:
This is my groovy build-step:
When I run the job, I get this error:
The user testrpm does have sudo rights. Where is the problem ?
I wouldn't install groovy on agent nodes. You should just use groovy wrapper which will download the groovy and run that without needing to install anything into directories jenkins doesn't have permissions for.
Short of that I would NOT grant sudo rights to testrpm either. That's going to be bad mojo. Instead you can add testrpm to a group that allows right access to /opt or /opt/groovy-4.0.0. You are unzipping something into a nested directory so you'll have to grant access to /opt to write to that directory which could be dangerous if you have other things in that directory. You may nest it in a subdirectory to isolate it from other things. If you do these steps on the machine using a user with sudo rights (not in your build script) then it should work:
sudo mkdir /opt/jenkins
sudo chgrp jenkins /opt/jenkins
sudo usermod -a -G jenkins testrpm
sudo chmod 770 /opt/jenkins
Another option would be to pick a directoy testrpm already has write access to that without needing to grant permissions to it.