Created
July 11, 2025 08:03
-
-
Save Java4all/a81e337e10166cf713feb580072e1dee to your computer and use it in GitHub Desktop.
groovy install pugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.model.* | |
import hudson.PluginWrapper | |
import java.nio.file.* | |
def pluginDir = new File(Jenkins.instance.rootDir, "plugins") | |
def pluginList = [ | |
[name: "git", version: "5.2.1"], | |
[name: "workflow-job", version: "2.40"] | |
] | |
pluginList.each { plugin -> | |
def pluginFile = new File("/opt/jenkins-plugins/${plugin.name}.hpi") | |
def destFile = new File(pluginDir, "${plugin.name}.jpi") | |
if (!destFile.exists()) { | |
println "Installing ${plugin.name} version ${plugin.version}" | |
Files.copy(pluginFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING) | |
} | |
} | |
Jenkins.instance.pluginManager.doCheckUpdatesServer() | |
Jenkins.instance.pluginManager.doLoad() | |
Jenkins.instance.restart() // Optional |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment