Top 5 Jenkins CI Tips you should know.

Jenkins-Logo

1. Tell Jenkins to run a specific project on a particular slave node

Set the “Restrict where this job can be run” check box in your job configuration and specify the name of your slave. If you add more slaves later, you can set labels for each slave and specify those in your job configs.

2. Restart Jenkins manually

You can use either of the following commands:

http://(jenkins_url)/safeRestart – Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.

http://(jenkins_url)/restart – Forces a restart without waiting for builds to complete.

You can even use the SafeRestart Plugin. Super useful tool.

Finally, via CLI:

  • sudo service jenkins start – To start the Jenkins
  • sudo service jenkins stop – To stop the Jenkins
  • sudo service jenkins restart – To restart the Jenkins
  • sudo service jenkins status – To know the status of Jenkins

3. Locked out of Jenkins

If you don’t have a lot of other configuration that you’d like to save, you can just delete %JENKINS_HOME%/config.xml and restart Jenkins to disable security. Otherwise, edit config.xml and set the values inside the useSecurity tags to false, then restart Jenkins.

I had this exact issue today on my Windows Jenkins server. Just removing the XML file and restarting did not work for me. So I had to:

  • Stop the service.
  • Check Task Manager to ensure the process is gone.
  • Edit the Config.XML file and change the useSecurity false (or you could delete the config.xml file).
  • Start the service again.

4. Default shell environment valuables
To get the list of all the variables that are available to shell scripts:

http://(jenkins_url)/env-vars.html

5. Jenkins Directory Structure

jenkins-directory_structure

Ref: https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins