Skip to content

Commit

Permalink
Fix dependency updates for Jenkins plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdecker1201 committed Oct 24, 2024
1 parent eba6ee7 commit 241da17
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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

0 comments on commit 241da17

Please sign in to comment.