]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
ansible: Update Jenkins plugins tasks
authorDavid Galloway <dgallowa@redhat.com>
Fri, 4 Aug 2017 15:28:47 +0000 (11:28 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Tue, 22 Aug 2017 14:42:45 +0000 (10:42 -0400)
 - Have to enable CLI to use jenkins-cli
 - Now compatible with ansible > v2

Signed-off-by: David Galloway <dgallowa@redhat.com>
ansible/roles/ansible-jenkins/handlers/main.yml
ansible/roles/ansible-jenkins/tasks/jenkins.yml
ansible/roles/ansible-jenkins/tasks/plugins.yml

index 759b833a9b55852ec20dbb4ecb9bd0e647065b56..1b67b76856dab1ba95afd29f8b42ef4ec15be447 100644 (file)
@@ -6,3 +6,8 @@
   service:
     name: nginx
     state: restarted
+
+- name: stop nginx
+  service:
+    name: nginx
+    state: stopped
index 4adb06011447093ef90bad9f0bb19bed4f0b0262..d018c12e9ffbe5a4322962d1d57bc3d8988d2713 100644 (file)
@@ -22,5 +22,7 @@
 - include: config.yml
 
 - include: plugins.yml
+  tags:
+    - plugins
 
 - include: config.yml
index 0077aa017bbb0532fd35c881a18b00f9dc865b1e..9308fe7737ccd2137c58238ca6df55b842ddd95d 100644 (file)
@@ -1,15 +1,46 @@
 ---
+- name: Make sure Jenkins CLI is enabled
+  blockinfile:
+    path: "{{ jenkins_lib }}/jenkins.CLI.xml"
+    create: yes
+    block: |
+      <?xml version='1.0' encoding='UTF-8'?>
+      <jenkins.CLI>
+        <enabled>true</enabled>
+      </jenkins.CLI>
+
+- name: Temporarily disable public http access
+  service:
+    name: nginx
+    state: stopped
+
+- name: Temporarily disable security so anonymous can use jenkins-cli
+  replace:
+    path: "{{ jenkins_lib }}/config.xml"
+    regexp: '<useSecurity>true</useSecurity>'
+    replace: '<useSecurity>false</useSecurity>'
+    backup: yes
+  register: original_jenkins_config
+
+- name: Restart Jenkins with no security so we can use jenkins-cli
+  service:
+    name: jenkins
+    state: restarted
+
 - name: List plugins
   shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} list-plugins | cut -f 1 -d ' '
   when: plugins is defined
   register: plugins_installed
+  # Jenkins takes a while to come back up
+  retries: 10
+  until: '"503" not in plugins_installed.stderr and plugins_installed.stdout != ""'
 
 - name: Install/update plugins
   shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} install-plugin {{ item }}
   when: plugins_installed.changed and plugins_installed.stdout.find('{{ item }}') == -1
-  with_items: plugins
-  notify:
-    - 'restart jenkins'
+  with_items: "{{ plugins }}"
+  # This is only here because the postbuildscript plugin is currently deprecated
+  ignore_errors: yes
 
 - name: List plugins to be updated
   shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} list-plugins | grep ')$' | cut -f 1 -d ' ' | sed ':a;N;$!ba;s/\n/ /g'
 
 - name: Update plugins
   shell: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ jenkins_port }} install-plugin {{ item }}
-  with_items: plugins_updates.stdout.split()
+  with_items: "{{ plugins_updates.stdout.split() }}"
   when: plugins_updates.stdout != ''
   ignore_errors: yes
-  notify:
-    - 'restart jenkins'
+
+- name: Restore original Jenkins config to re-enable auth
+  copy:
+    src: "{{ original_jenkins_config.backup_file }}"
+    dest: "{{ jenkins_lib }}/config.xml"
+    remote_src: yes
+    owner: jenkins
+    group: jenkins
+
+- name: Restart Jenkins with security
+  service:
+    name: jenkins
+    state: restarted
+
+- name: Re-enable public http access
+  service:
+    name: nginx
+    state: started