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

Add jenkins_restart_method to allow a safe restart to be performed. #391

Merged
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 @@ -128,6 +128,10 @@ Changes made to the Jenkins systemd override.conf file; the default set of chang

If you are running Jenkins behind a proxy server, configure these options appropriately. Otherwise Jenkins will be configured with a direct Internet connection.

jenkins_restart_method: `service`

You can change `jenkins_restart_method` to `safe-restart`, if you want to make sure all running jobs on the Jenkins server are completed. Otherwise `service` will restart the Jenkins systemd-service.

## Dependencies

None.
Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ jenkins_proxy_noproxy:

jenkins_init_folder: "/etc/systemd/system/jenkins.service.d"
jenkins_init_file: "{{ jenkins_init_folder }}/override.conf"

jenkins_restart_behavior: "service"
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: restart jenkins
service: name=jenkins state=restarted
include_tasks: tasks/restart.yml

- name: configure default users
template:
Expand Down
8 changes: 8 additions & 0 deletions tasks/restart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: restart jenkins via service
service: name=jenkins state=restarted
when: jenkins_restart_behavior == 'service'

- name: safe-restart jenkins via CLI
ansible.builtin.command: java -jar {{ jenkins_jar_location }} -auth {{ jenkins_admin_username }}:{{ jenkins_admin_password }} -s http://{{ jenkins_hostname }}:{{ jenkins_http_port }} safe-restart

Check warning on line 7 in tasks/restart.yml

View workflow job for this annotation

GitHub Actions / Lint

7:151 [line-length] line too long (197 > 150 characters)
when: jenkins_restart_behavior == 'safe-restart'