Jenkins: List All Jobs – Groovy Script

The easiest way to get a list of all Jenkins jobs is by executing an appropriate Groovy script using a Jenkins script console feature.

This note shows two examples of Groovy scripts for listing the Jenkins jobs.

The first script simply prints the list of all Jenkins jobs while the second one additionally lets you to identify how the last build of each job was triggered, e.g. manually by user, triggered by commit, by schedule etc. (more…)

Jenkins: Hide Passwords – MaskPasswordsBuildWrapper

For some reason you may not want to store credentials in Jenkins using the Credentials Plugin.

Nevertheless, you still may need to hide sensitive data, like passwords or secret keys from the console output in Jenkins.

One of the possible solution is to wrap the parts of the code you want to hide with set +x (stop showing the output) and set -x (resume showing the output).

But the more elegant and efficient solution is to use the Mask Passwords Plugin, that allows masking passwords that may appear in the console.

In this note i will show an example of how to hide passwords in Jenkins console output using the MaskPasswordsBuildWrapper from the Jenkins declarative pipeline. (more…)

Jenkins Pipeline: Input Step – Example

In Jenkins declarative pipelines it is possible to prompt a user for an interactive input by creating the input step.

For example, at some stage of the Jenkins pipeline you may want to ask a user to provide the credentials.

The user input can be saved as an environment variable and used in the next steps.

Bellow i will show an example of the Jenkins pipeline with the input step. (more…)

Jenkins: Schedule – Build Periodically – Parameters

A Job in Jenkins can be scheduled for periodical builds in a declarative pipeline i.e. Jenkinsfile using a string in a cron-style syntax (with minor differences) defined in the triggers directive, for example triggers{cron('0 */3 * * *')}.

This note shows the examples of how to build Jenkins jobs and multi-branch pipelines periodically and how to schedule Jenkins jobs with parameters.

Also it shows the Jenkins cron syntax with examples. (more…)

Jenkins: Reset Admin Password

If you have forgotten the Jenkins admin password and can’t log in to a Jenkins user interface (UI) as administrator, you can connect to a Jenkins server via SSH and reset the Jenkins admin password.

The simplest solution is to completely disable security in /var/lib/jenkins/config.xml file, access the Jenkins UI omitting authentication and rest the Jenkins admin password. (more…)

Jenkins: Default Password & Username

The first time you start Jenkins, the configuration is created along with the initial default administrator account.

If for some reason you have skipped the user-creation step in the setup wizard, you can use the default admin username and password to access the Jenkins UI.

The Jenkins default password is stored in the $JENKINS_HOME/secrets/initialAdminPassword file (the exact location of the Jenkins default password is indicated in the Jenkins console log). (more…)

Jenkins Pipeline: Conditionally Define Variables – Groovy Script

The Groovy scripting language supports conditional structures, that can be used in Jenkins pipelines.

Assume that you have a parametrized Jenkins job and in a Jenkinsfile you have a variable that should be defined depending on provided parameters.

Here is an example of how to conditionally define variables in a Jenkins pipeline using the Groovy scripting language syntax. (more…)