Skip to content

Instantly share code, notes, and snippets.

@Java4all
Last active July 11, 2025 08:55
Show Gist options
  • Save Java4all/dcb43edbd70729a3d4bf94b7cfb293e9 to your computer and use it in GitHub Desktop.
Save Java4all/dcb43edbd70729a3d4bf94b7cfb293e9 to your computer and use it in GitHub Desktop.
# Directory where plugin .hpi files will be stored
# File: plugins.yaml
# Define plugins with specific versions
# Example YAML file to track plugin versions
---
plugins:
- name: git
version: 5.1.0
- name: credentials
version: 1271.v54b_1c2c6388a_
- name: ssh-slaves
version: 1.32.0
# download_plugins.sh
# Run this shell script to download specified versions of Jenkins plugins
#!/bin/bash
set -euo pipefail
REPO_URL="https://raw.githubusercontent.com/YOUR_GITHUB_USER/YOUR_REPO_NAME/main/plugins.yaml"
PLUGINS_YAML="plugins.yaml"
JENKINS_PLUGIN_DIR=plugins
UPDATE_CENTER="https://updates.jenkins.io/download/plugins"
echo "📥 Downloading plugins.yaml from GitHub..."
curl -fsSL "$REPO_URL" -o "$PLUGINS_YAML"
mkdir -p "$JENKINS_PLUGIN_DIR"
for row in $(yq -r '.plugins[] | @base64' "$PLUGINS_YAML"); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
name=$(_jq '.name')
version=$(_jq '.version')
echo "⬇ Downloading $name:$version"
curl -fsSL "$UPDATE_CENTER/$name/$version/$name.hpi" -o "$JENKINS_PLUGIN_DIR/$name.hpi"
done
# init.groovy.d/install_plugins.groovy
// Place this in Jenkins /var/lib/jenkins/init.groovy.d/
import jenkins.model.*
import hudson.PluginWrapper
Jenkins.instance.pluginManager.doCheckUpdatesServer()
File pluginDir = new File(Jenkins.instance.rootDir, "plugins")
pluginDir.listFiles().each { file ->
if (file.name.endsWith(".hpi")) {
def shortName = file.name.replace(".hpi", "")
if (!Jenkins.instance.pluginManager.getPlugin(shortName)) {
println "Installing plugin: ${shortName}"
Jenkins.instance.pluginManager.dynamicLoad(file)
}
}
}
Jenkins.instance.save()
println "Plugin installation completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment