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.
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.
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 .
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.
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()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With