Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency updates for Jenkins plugins. #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Jenkins plugins to be installed automatically during provisioning. Defaults to e

Whether Jenkins plugins to be installed should also install any plugin dependencies.

jenkins_plugin_update_dependencies: true

Whether the dependencies of Jenkins plugins should be updated. Together with setting `jenkins_plugins_state` to `latest`, this will ensure that all your plugins and dependencies are up to date.

jenkins_plugins_state: present

Use `latest` to ensure all plugins are running the most up-to-date version. For any plugin that has a specific version set in `jenkins_plugins` list, state `present` will be used instead of `jenkins_plugins_state` value.
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jenkins_plugins_state: present
jenkins_plugin_updates_expiration: 86400
jenkins_plugin_timeout: 30
jenkins_plugins_install_dependencies: true
jenkins_plugin_update_dependencies: false
jenkins_updates_url: "https://updates.jenkins.io"

jenkins_admin_username: admin
Expand Down
25 changes: 25 additions & 0 deletions tasks/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@
until: plugin_result is success
retries: 3
delay: 2

- name: Update Jenkins plugins dependencies
when: jenkins_plugin_update_dependencies
ansible.builtin.shell: |
set -o pipefail
# This will ensure that only plugins with a pending update are updated.
# The output of `list-plugin` is a list of all plugins, but only those with a closing bracket ")" at the end have a pending update.
UPDATE_LIST=$( \
java -jar {{ jenkins_jar_location }} \
-auth {{ jenkins_admin_username }}:{{ jenkins_admin_password }} \
-s http://{{ jenkins_hostname }}:{{ jenkins_http_port }} \
list-plugins | \
grep -e ')$' | \
awk '{ print $1 }' \
);
if [ ! -z "${UPDATE_LIST}" ]; then
echo Updating Jenkins Plugins: ${UPDATE_LIST};
java -jar {{ jenkins_jar_location }} \
-auth {{ jenkins_admin_username }}:{{ jenkins_admin_password }} \
-s http://{{ jenkins_hostname }}:{{ jenkins_http_port }} \
install-plugin ${UPDATE_LIST};
fi
register: result
changed_when: result.stdout.startswith("Updating Jenkins Plugins:")
notify: restart jenkins
Loading