Jenkins allows adding groovy scripts for initialization, which means these scripts will run every time Jenkins starts.
The jenkins server automatically looks for groovy.d
folder under the home dir of where Jenkins run from e.g. /var/lib/jenkins/groovy.d
or /root/.jenkins/groovy.d
if running in a container, and any groovy script in folder get executed anytime jenkins starts.
Its a pretty handy way of automating Jenkins installation; lets say you want your CI setup to be automated, like everytime you install your jenkins environment, it should be pre-configured with certain user accounts created, have LDAP configured automatically or some global properties set.
Groovy is an easy way of calling Jenkins base classes of Java without getting to know much of Java itself ;)
I have scripts for :
- Creating user accounts.
- Creating global credentials (for ssh , username/password etc).
- Getting the API key of a user ( this is pretty useful because if you use (Jenkins Job Builder )[https://github.com/openstack-infra/jenkins-job-builder.git] for setting up your CI , for the credential .ini file , you will need the API key so why not get it from a groovy script :) )
- Setting the global security , either LDAP , or jenkins own database etc.
- Setting global authorization matrix for groups like
anonymous
,authenticated
or any specific user. - Get a credential ID of a global credential, again extremely useful when you use Jenkins Job BUilder and in git SCM, you need to specify (Credential ID of ssh key for git to use in cloning some private repos)[http://docs.openstack.org/infra/jenkins-job-builder/scm.html], this script will do it for you .
Cheers :)