Skip to content

Instantly share code, notes, and snippets.

@Java4all
Last active July 9, 2025 06:51
Show Gist options
  • Save Java4all/9699bc1f421e4000956f322e3f29124e to your computer and use it in GitHub Desktop.
Save Java4all/9699bc1f421e4000956f322e3f29124e to your computer and use it in GitHub Desktop.
Jenkins plugins management options
1. Jenkins Plugin Manager CLI
The Jenkins Plugin Manager CLI (jenkins-plugin-manager) is officially recommended, modern, and robust:
- Better dependency resolution.
- Officially supported by Jenkins.
- YAML-based plugin configuration.
2. Step-by-step Automation Guide:
Overall workflow:
- Maintain plugins.yaml on GitHub.
- EC2 instance (or Ansible automation) fetches plugins.yaml.
- Use jenkins-plugin-manager with authentication to Jenkins to install/update plugins.
Step 1: Prepare plugins.yaml on GitHub
Create a plugins.yaml file in your repo:
plugins:
- artifactId: workflow-aggregator
source:
version: latest
- artifactId: git
source:
version: latest
- artifactId: blueocean
source:
version: 1.27.12
- artifactId: configuration-as-code
source:
version: 1714.v09593e830cfa
Step 2: Download and Configure jenkins-plugin-manager on EC2
Download the latest release:
wget https://github.com/jenkinsci/plugin-installation-manager-tool/releases/latest/download/jenkins-plugin-manager-2.13.0.jar -O /tmp/jenkins-plugin-manager.jar
Step 3: Jenkins Authentication Setup (API Token):
You need Jenkins credentials (username/API token):
a. Log into Jenkins.
b. Manage Jenkins → Manage Users → your-user → Configure
c. Under API Token, click Add New Token, name it (e.g., plugin-manager-token).
d. Copy the generated token securely.
Step 4: Deployment
Option 1 Automate with Ansible (Including Authentication)
Ansible playbook example:
inventory.ini file:
[jenkins]
jenkins_ec2 ansible_host=<your-ec2-ip> ansible_user=ubuntu
jenkins-plugins.yml
Ansible playbook file:
---
- hosts: jenkins
vars:
jenkins_url: "http://localhost:8080"
plugin_manager_url: "https://github.com/jenkinsci/plugin-installation-manager-tool/releases/latest/download/jenkins-plugin-manager-2.13.0.jar"
plugins_yaml_url: "https://raw.githubusercontent.com/<username>/<repo>/main/plugins.yaml"
jenkins_cli_jar: "/tmp/jenkins-plugin-manager.jar"
jenkins_user: "admin"
jenkins_token: "<your-jenkins-api-token>"
tasks:
- name: Install OpenJDK
apt:
name: openjdk-17-jre
state: present
become: yes
- name: Download Jenkins Plugin Manager CLI
get_url:
url: "{{ plugin_manager_url }}"
dest: "{{ jenkins_cli_jar }}"
- name: Download plugins.yaml from GitHub
get_url:
url: "{{ plugins_yaml_url }}"
dest: "/tmp/plugins.yaml"
- name: Install Jenkins plugins using Jenkins Plugin Manager CLI
command: >
java -jar {{ jenkins_cli_jar }}
--war /usr/share/java/jenkins.war
--plugin-file /tmp/plugins.yaml
--jenkins-url {{ jenkins_url }}
--username {{ jenkins_user }}
--password {{ jenkins_token }}
--verbose
notify: Restart Jenkins
handlers:
- name: Restart Jenkins
service:
name: jenkins
state: restarted
become: yes
Replace <username>/<repo> and <your-jenkins-api-token> accordingly.
Step 4.1: Run the Automation
Deploy plugins:
ansible-playbook -i inventory.ini jenkins-plugins.yml
Option 2: EC2 User Data Script (Cloud-init automation):
It will run under userdata scrip during of provisioning EC2 instances:
Automation script:
#!/bin/bash
# Install Java and Jenkins
sudo apt update && sudo apt install -y openjdk-17-jre wget
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
echo 'deb https://pkg.jenkins.io/debian-stable binary/' | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt update && sudo apt install -y jenkins
# Download Plugin Manager CLI
wget https://github.com/jenkinsci/plugin-installation-manager-tool/releases/latest/download/jenkins-plugin-manager-2.13.0.jar -O /tmp/jenkins-plugin-manager.jar
# Wait Jenkins to start (may take ~1 minute)
sleep 60
# Download plugins.yaml
wget https://raw.githubusercontent.com/<username>/<repo>/main/plugins.yaml -O /tmp/plugins.yaml
# Install Plugins
java -jar /tmp/jenkins-plugin-manager.jar \
--war /usr/share/java/jenkins.war \
--plugin-file /tmp/plugins.yaml \
--jenkins-url http://localhost:8080 \
--username admin \
--password <your-api-token> \
--verbose
# Restart Jenkins
sudo systemctl restart jenkins
Maintaining the Plugin List via GitHub:
Update your plugins.yaml directly in GitHub.
Run the Ansible playbook or re-run the automation to apply updates.
Security Best Practices:
- Always protect your Jenkins API token securely.
- Consider using AWS Secrets Manager or Ansible Vault for tokens.
- Never commit API tokens directly into public repositories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment