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 […]
jenkins
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 […]
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 […]
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 […]
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: 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 […]
Jenkins: Scan Multibranch Pipeline Without Build
If you click on the “Scan Multibranch Pipeline Now” link in the Jenkins dashboard to discover the new branches, by default, this will automatically trigger builds for all newly discovered branches. In this short note i am showing how to disable automatic job triggering during SCM scanning for the new branches.
Jenkins: Credentials Plugin – Decrypt Password
Jenkins credentials plugin hides secrets like passwords and SSH or API keys by encrypting them. Nevertheless these credentials can be decrypted and printed in a plain text. In this note i will show 2 ways of how to decrypt secrets masked by Jenkins credentials plugin.
Jenkins Pipeline: How to Define a Variable – Jenkins Variables
Variables in a Jenkinsfile can be defined by using the def keyword. Such variables should be defined before the pipeline block starts. When variable is defined, it can be called from the Jenkins declarative pipeline using ${…} syntax.
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 […]