How to install jenkins plugins from command line?

后端 未结 4 452
孤街浪徒
孤街浪徒 2020-12-13 19:43

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         


        
相关标签:
4条回答
  • 2020-12-13 20:19

    If you don't find some straight forward command for installing plugins. Please take a look at this link: How to install a plugin in Jenkins manually?

    But it needs to download the plugin first(*.hpi file) and run it manually.

    0 讨论(0)
  • 2020-12-13 20:32

    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.

    0 讨论(0)
  • 2020-12-13 20:36
    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()
     }
    
    0 讨论(0)
  • 2020-12-13 20:38

    Since Sept 2019, you can also use the Plugin Installation Manager Tool. It takes a yaml file listing the plugins, and downloads plugins to a folder of your choice. There is no need to have a running Jenkins instance. You can specify the plugin versions in the yaml file, but be aware of JENKINS-60205.

    Get the plugin manager:

    version=1.0.1
    curl \
        -L \
        -X GET "https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-$version/jenkins-plugin-manager-$version.jar" \
        -o jenkins-plugin-manager-$version.jar
    

    Download the plugins:

    java -jar jenkins-plugin-manager-$version.jar \
        --plugin-download-directory pluginsFolder \
        --plugin-file plugins.yml \
        --war jenkins.war
    

    The plugins are in the pluginsFolder.

    0 讨论(0)
提交回复
热议问题