When we use CLI commands like safe-restart or keep-build, the authentication cache provided by login in addition to -remoting is not working. It's due to the different way to manage those CLI commands compared to the regular one, that inherits from the CLICommand class.
Example:
Configure an instance with a user (login=user, password=user), and a project called "p".
> java -jar jenkins-cli.jar -s http://localhost:8080/jenkins -remoting login --username user --password user > java -jar jenkins-cli.jar -s http://localhost:8080/jenkins -remoting build p > java -jar jenkins-cli.jar -s http://localhost:8080/jenkins -remoting keep-build p 1
The build will work but the keep-build will fail because the anonymous user does not have the Run/Update permission.
- links to