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
It's really good article..Thanks for sharing.
ReplyDeleteDevOps Training
DevOps Online Training