Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install jenkins plugins from command line?

Is there any option to install jenkins plugins from command line ?

I found a command for this after a bit google search :

java -jar /var/lib/jenkins/jenkins.war -s http://127.0.0.1:8080/ install-plugin ${Plugin_Name}

But it's not working.

like image 843
Arun Ramachandran Avatar asked Jan 13 '16 07:01

Arun Ramachandran


People also ask

How do I install Jenkins plugins?

Step 1: To install a plugin, go to the Jenkins Dashboard and click on Manage Jenkins. Step 2: Scroll down and select Manage Plugins. Step 3: Go to the Available tab and in the filter option, search for the plugins which you want to install. Step 4: Select that plugins and click on Install without restart button.

Where is Jenkins plugin command line?

By default it will be in ~/. cache/jenkins-plugin-management-cli , if the user doesn't have a home directory when it will go to: $(pwd)/. cache/jenkins-plugin-management-cli .


2 Answers

As per the Jenkins command line interface documentation, you need to use the client JAR file (not the server WAR file you're using), which you can obtain directly from Jenkins, e.g. via the links on http://localhost:8080/cli

Then you can run the command using this JAR:

java -jar jenkins-cli.jar -s http://127.0.0.1:8080/ install-plugin <name>

This will download install the plugin you want, along with any of its dependencies.

like image 191
Christopher Orr Avatar answered Oct 16 '22 08:10

Christopher Orr


import jenkins.model.* 
import java.util.logging.Logger

def logger = Logger.getLogger("") 
def installed = false 
def initialized = false

def pluginParameter="gitlab-plugin hipchat swarm" 
def plugins =pluginParameter.split() 
logger.info("" + plugins) 
def instance =Jenkins.getInstance() 
def pm = instance.getPluginManager() 
def uc =instance.getUpdateCenter() 
uc.updateAllSites()

plugins.each {   logger.info("Checking " + it)   if
(!pm.getPlugin(it)) {
    logger.info("Looking UpdateCenter for " + it)
    if (!initialized) {
      uc.updateAllSites()
      initialized = true
    }
    def plugin = uc.getPlugin(it)
    if (plugin) {
      logger.info("Installing " + it)
        plugin.deploy()
      installed = true
    }   } }

if (installed) 
   {  
      logger.info("Plugins installed, initializing a   restart!")   
       instance.save()  
       instance.doSafeRestart()
 }
like image 6
Ijaz Ahmad Avatar answered Oct 16 '22 07:10

Ijaz Ahmad