-
Notifications
You must be signed in to change notification settings - Fork 7
/
jenkins_jobs.yml
178 lines (159 loc) · 5.43 KB
/
jenkins_jobs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# vim: ft=ansible
---
######################
# Deploy jobs via JJB
######################
- hosts: jenkins_master
become: true
tags:
- jenkins_master
- jenkins_jobs
vars_files:
- "{{ inventory_dir }}/{{ vars_files_relative }}/vars/main.yml"
- ~/.ansible/vars/toad_vars.yml
pre_tasks:
- name: Validate Git is installed
package:
name: git
state: present
- name: config get http.sslVerify
git_config:
name: http.sslVerify
scope: global
register: http_sslVerify
- name: config http.sslVerify false
git_config:
name: http.sslVerify
scope: global
value: false
when: http_sslVerify.config_value != 'false'
- name: Locally clone Jenkins job configs
git:
repo: "{{ jenkins_job_config_git_src }}"
dest: "{{ jenkins_job_config_file_src }}"
version: "{{ jenkins_job_config_git_version }}"
force: yes
accept_hostkey: yes
delegate_to: localhost
changed_when: false
tags:
- clone_configs
become: false
- name: Locally clone Jenkins jobs
git:
repo: "{{ jenkins_job_builder_git_jobs_src }}"
dest: "{{ jenkins_job_builder_file_jobs_src }}"
version: "{{ jenkins_job_builder_git_jobs_version }}"
force: yes
accept_hostkey: yes
delegate_to: localhost
changed_when: false
tags:
- clone_jobs
become: false
- name: Change all tasks to jenkins slave (docker)
replace:
dest: "{{ jenkins_job_builder_file_jobs_src }}/project-toad.yaml"
regexp: "partner: master"
replace: "partner: toad"
delegate_to: localhost
when: deploy_type is defined and deploy_type == 'docker'
- name: Create folder to store config
file:
path: "{{ jenkins_job_config_file_dest }}"
state: directory
recurse: yes
mode: "0755"
owner: jenkins
group: jenkins
- name: Synchronize job config to remote server
synchronize:
src: "{{ jenkins_job_config_file_src }}"
dest: "{{ jenkins_job_config_file_dest }}"
archive: yes
when: deploy_type is not defined or deploy_type != 'docker'
tags:
- sync_jobs
- name: Synchronize job config to remote server (docker)
command: rsync -r "/opt/toad/{{ jenkins_job_config_file_src }}" "{{ jenkins_job_config_file_dest }}"
when: deploy_type is defined and deploy_type == 'docker'
tags:
# Skip ANSIBLE0006. Synchronize module is not available docker.
- skip_ansible_lint
- sync_jobs
- name: Locally clone TOAD envs
git:
repo: "{{ jenkins_job_baremetal_env_git_src }}"
dest: "{{ jenkins_job_baremetal_env_file_src }}"
version: "{{ jenkins_job_baremetal_env_git_version }}"
force: yes
accept_hostkey: yes
delegate_to: localhost
changed_when: false
tags:
- clone_jobs
become: false
- name: Create folder to store config
file:
path: "{{ jenkins_job_baremetal_file_dest }}"
state: directory
recurse: yes
mode: "0755"
owner: jenkins
group: jenkins
- name: Synchronize baremetal envs to remote server
synchronize:
src: "{{ jenkins_job_baremetal_env_file_src }}/{{ jenkins_job_baremetal_env_path }}"
dest: "{{ jenkins_job_baremetal_file_dest }}"
archive: yes
when: deploy_type is not defined or deploy_type != 'docker'
- name: Synchronize baremetal envs to remote server (docker)
command: rsync -r "/opt/toad/{{ jenkins_job_baremetal_env_file_src }}" "{{ jenkins_job_baremetal_file_dest }}"
when: deploy_type is defined and deploy_type == 'docker'
tags:
# Skip ANSIBLE0006. Synchronize module is not available docker.
- skip_ansible_lint
roles:
- { role: 'leifmadsen.jenkins-job-builder', tags: sync_jobs }
post_tasks:
- name: Synchronize JJB config to remote server
become: true
become_user: jenkins
synchronize:
delete: yes
dest: "{{ jenkins_job_builder_file_jobs_dest }}"
perms: yes
src: "{{ item }}"
when: jenkins_job_builder_job_files != "" and
(deploy_type is not defined or deploy_type != 'docker')
with_items: "{{ jenkins_job_builder_job_files }}"
notify:
- Check jenkins
- Reload jenkins-jobs
tags:
- sync_jobs
- name: prepare Synchronize JJB config to remote server (docker)
file:
path: "{{ jenkins_job_builder_file_jobs_dest }}"
group: jenkins
owner: jenkins
when: jenkins_job_builder_file_jobs_src != "" and
(deploy_type is defined and deploy_type == 'docker')
- name: Synchronize JJB config to remote server (docker)
become: true
become_user: jenkins
command: rsync -r "{{ item }}" "{{ jenkins_job_builder_file_jobs_dest }}"
when: jenkins_job_builder_file_jobs_src != "" and
(deploy_type is defined and deploy_type == 'docker')
with_items: "{{ jenkins_job_builder_file_jobs_src_docker }}"
notify:
- Check jenkins
- Reload jenkins-jobs
tags:
# Skip ANSIBLE0006. Synchronize module is not available docker.
- skip_ansible_lint
- sync_jobs
- name: Results of JJB reload
debug:
var: reload_jenkins_jobs_result.stderr
when: reload_jenkins_jobs_result is defined