[AETHER-853] - Install the Jenkins plugins by Ansible playbook
Change-Id: I90d38e0346a87750b68f0ffe5fa89110bdde5249
diff --git a/README.md b/README.md
index d13f181..38d91b0 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,24 @@
- "127.0.0.1"
- "localhost"
+# Jenkins plugin setting, all list plugin will be installed into the Jenkins and we can specify the version as well.
+jenkins_plugins:
+ - name: ec2
+ - name: crowd2
+ version: 2.0.0
+ - name: docker-workflow
+ - name: gerrit-trigger
+ - name: workflow-aggregator
+ - name: matrix-auth
+ - name: config-file-provider
+ - name: ws-cleanup
+ - name: ssh-agent
+ - name: postbuildscript
+ - name: git
+ - name: description-setter
+ - name: build-timestamp
+ - name: run-condition
+
## Example Playbook
```yaml
@@ -49,8 +67,12 @@
vars:
jenkins_admin_username: "admin"
jenkins_admin_password: "change_me"
- jenkins_proxy_host: "https://site.example.org"
- jenkins_proxy_port: "443"
+ jenkins_plugins:
+ - name: ec2
+ - name: crowd2
+ - name: docker-workflow
+ - name: gerrit-trigger
+ - name: workflow-aggregator
roles:
- jenkins
diff --git a/defaults/main.yml b/defaults/main.yml
index 7d5a9a8..61fd715 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -26,3 +26,9 @@
jenkins_admin_username: "admin"
jenkins_admin_password: "changeme"
+
+# Use the version filed to specify the version, otherwise latest.
+jenkins_plugins: []
+# - name: "build-pipeline-plugin"
+# - name: "crowd2"
+# version: 2.0.2
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
index 6a2f161..1594cdf 100644
--- a/molecule/default/converge.yml
+++ b/molecule/default/converge.yml
@@ -6,6 +6,15 @@
- name: Converge
hosts: all
+ vars:
+ jenkins_admin_username: "admin"
+ jenkins_admin_password: "change_me"
+ jenkins_plugins:
+ - name: ec2
+ - name: crowd2
+ - name: docker-workflow
+ - name: gerrit-trigger
+ - name: workflow-aggregator
tasks:
- name: "Include jenkins"
include_role:
diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml
index 207edad..a00c87a 100644
--- a/molecule/default/verify.yml
+++ b/molecule/default/verify.yml
@@ -9,8 +9,14 @@
vars:
jenkins_localhost: "127.0.0.1:8080"
jenkins_admin_username: "admin"
- jenkins_admin_password: "changeme"
+ jenkins_admin_password: "change_me"
jenkins_job_builder_conf: "/tmp/jenkins.conf"
+ jenkins_plugins:
+ - name: ec2
+ - name: crowd2
+ - name: docker-workflow
+ - name: gerrit-trigger
+ - name: workflow-aggregator
tasks:
- name: Check Jenkins instance accessibility
uri:
@@ -44,10 +50,24 @@
- name: List jobs via JJB tools
command: "jenkins-jobs --conf {{ jenkins_job_builder_conf }} list"
- register: plugins_contents
+ register: jobs_contents
changed_when: false
- name: Assert we are able to access Jenkins with admin username and password.
assert:
that:
- - "'INFO:root:Matching jobs: 0' in plugins_contents.stderr"
+ - "'INFO:root:Matching jobs: 0' in jobs_contents.stderr"
+
+ - name: Save installed plugins to plugins_info.yaml
+ command: "jenkins-jobs --conf {{ jenkins_job_builder_conf }} get-plugins-info"
+ changed_when: false
+
+ - name: read the plugin_info file
+ shell: cat plugins_info.yaml
+ register: plugins_contents
+
+ - name: Assert Jenkins install all required plugins
+ assert:
+ that:
+ - "' shortName: {{ item.name }}' in plugins_contents.stdout_lines"
+ with_items: "{{ jenkins_plugins }}"
\ No newline at end of file
diff --git a/tasks/main.yml b/tasks/main.yml
index 1860396..fdc9e3a 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -39,3 +39,18 @@
file:
path: "{{ jenkins_home }}/init.groovy.d/basic-security.groovy"
state: absent
+
+- name: Install plugins
+ jenkins_plugin:
+ name: "{{ item.name }}"
+ version: "{{ item.version | default(omit) }}"
+ url_username: "{{ jenkins_admin_username }}"
+ url_password: "{{ jenkins_admin_password }}"
+ url: "http://{{ jenkins_localhost }}"
+ register: my_jenkins_plugin_versioned
+ with_items: "{{ jenkins_plugins }}"
+ notify: restart-jenkins
+ register: plugin_result
+ until: plugin_result is success
+ retries: 3
+ delay: 2