Create a Jenkins user from the command-line with Jenkins CLI and Groovy

I have not been able to find examples on how to create users in Jenkins from the API.

Fortunately, the Jenkins CLI allows to run arbitrary Groovy scripts against the Jenkins instance so it was a matter of finding the right API call to achieve that.

These are the two commands needed:


wget http://localhost:8080/jnlpJars/jenkins-cli.jar

echo 'hpsr=new hudson.security.HudsonPrivateSecurityRealm(false); hpsr.createAccount("dummyuser", "dummypassword")' | java -jar jenkins-cli.jar -s http://localhost:8080 groovy =