Sunday, January 27, 2019

Error Anonymous is missing the Overall/Read permission

In automation command line tools play an important role. Jenkins has an in-build Command line interface 'Jenkins-cli' Jar. Running Command line require proper authentication to the Jenkins server to execute the given commands. Authentication with an -auth option, takes a username:apitoken as an argument.

If you are observing 'ERROR: anonymous is missing the Overall/Read permission' means either you are not authorized or proper authentication is missing for user on Jenkins Server.


Ways to Authenticate to Jenkins Server via command Line CLI


Jenkins Authentication using username:token

java -jar jenkins-cli.jar [-s JENKINS_URL] -auth username:token command
-auth [ USER:SECRET ] :

Specify username and either password or API token (or load from them both from a file), for use with -http, or -remoting but only when the JNLP agent port is disabled. Passing credentials by a file is recommended.



Jenkins Load Authentication Data from File using '@'

java -jar jenkins-cli.jar [-s JENKINS_URL] -auth @/some/directory command
-auth [ @FILE ] :

Load username and password from a file, for use with -http, or -remoting but only when the JNLP agent port is disabled. Passing credentials by a file is recommended.



Jenkins Authentication using SSH Public Key in your Jenkins user account


We can either enter passphrase on promoting the error or we can pass it along with the command
java -jar jenkins-cli.jar [-s JENKINS_URL] -i path/to/Key command
 -i KEY : 
SSH private key file used for authentication (for use with -ssh or -remoting)



Thursday, January 24, 2019

Jenkins Retry Failed Builds

We will use Jenkins Naginator Plugin to rerun the Failed/Unstable builds. This plugin allows you to automatically reschedule a build after a build failure.

Configure

  • Go to Manage Jenkins > Manage Plugin > Available Tab > Search 'Naginator' and install and restart


  • After installing the plugin, add the Post-Build action "Retry build after failure" on your Jenkins Job configuration page.


  • Set Build Retry

Above set Build retry screenshot shows that:

  • Job is enabled to rerun for unstable as well as Failure builds
  • Delay the build execution by Fixed 60 seconds
  • Maximum number of successive failed builds count is set to 3 (Limits successive failed build retries. Set to 0 for no limit.)

Install Jenkins Plugin via Command Line CLI

Jenkins has a built-in command line interface CLI that allows us to access Jenkins from shell. To do so we have to download jenkins-cli.jar on the jenkins server.

Download Jenkins CLI Jar on Windows:



You can download the JAR file for the client from the URL "/jnlpJars/jenkins-cli.jar" on your Jenkins server.

e.g. My Jenkins server is installed on my local machine so url will be: 

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

https://example.com/jnlpJars/jenkins-cli.jar

Download Jenkins CLI Jar on Linux


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


How to Install Plugin via CLI


Now to install Jenkins Plugin using command line we have to run  Jenkins CLI jar with Jenkins server URL, install-plugin argument and plugin name. 

Windows:

java -jar C:\path\to\jarFile\jenkins-cli.jar -s http://localhost:8080 install-plugin htmlpublisher

Linux:

java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin htmlpublisher

Restart the Jenkins Server

java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart


Error 'anonymous is missing the Overall/Read permission'


If you notice Error 'anonymous is missing the Overall/Read permission' while executing any commands, means authentication is missing. Please use authentication token in the request

Use: -auth username:password

java -jar jenkins-cli.jar -auth username:password -s http://localhost:8080 install-plugin htmlpublisher


java -jar jenkins-cli.jar -auth username:password -s http://localhost:8080 safe-restart

How to Install Plugin in Jenkins via GUI

There are 2 ways to Install Plugins in Jenkins:

  1. Install Jenkins plugin via GUI
  2. Install Jenkins plugin via CLI (Command Line Interface)
To install plugin via CLI Please refer Post: Install Jenkins Plugin via Command Line CLI

How to Install Plugin via GUI



  • Login to Jenkins Server

  • Go to Manage Jenkins

  • Go to Mange Plugins

  • Go to Available Tab > Search Plugin > Select the required plugin from the results > Install either without restart or with restart

  • Successfully Installed