diff --git a/README.md b/README.md index 6542143..73499b5 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,12 @@ adapt. ## TODO - stop execution if host is running an untested system ? -- use jenkins-cli to maintain credentials.xml ? It's not really easy to manipulate in Ansible at the moment... -- lookup more throroughfully at [configuration as code plugin](https://plugins.jenkins.io/configuration-as-code/) - update plugins, or at least display a warning when they are not up to date. - integrate docker-plugin nicely +- lookup more throroughfully at [configuration as code plugin](https://plugins.jenkins.io/configuration-as-code/) +- test [Job DSL](https://plugins.jenkins.io/job-dsl/) (but jenkins-php.org gives only the .xml and job-dsl can't yet generate the groovy code of an existing job) +- use jenkins-cli to maintain credentials.xml ? It's not really easy to manipulate in Ansible at the moment... + ## License diff --git a/roles/jenkins-php-v1/handlers/main.yml b/roles/jenkins-php-v1/handlers/main.yml index ed98147..e7f189e 100644 --- a/roles/jenkins-php-v1/handlers/main.yml +++ b/roles/jenkins-php-v1/handlers/main.yml @@ -1,8 +1,7 @@ --- -- name: restart jenkins - service: name=jenkins state=restarted - +# Avoid to use this one as it doesn't wait for Jenkins to be ready +# and thus, next invocation of jenkins-cli may fail. - name: safe-restart jenkins shell: "{{ jenkins_cli_command }} safe-restart" @@ -10,5 +9,9 @@ - name: safe-restart jenkins and wait import_tasks: roles/jenkins-php-v1/tasks/include_saferestartandwait.yml +# As of now (Ansible 2.7.7), Ansible doesn't support blocks in handlers +- name: system restart jenkins and wait + import_tasks: roles/jenkins-php-v1/tasks/include_restartandwait.yml + - name: reload nginx service: name=nginx state=reloaded diff --git a/roles/jenkins-php-v1/tasks/60_install-nginx-proxy.yml b/roles/jenkins-php-v1/tasks/60_install-nginx-proxy.yml index c066176..40743c3 100644 --- a/roles/jenkins-php-v1/tasks/60_install-nginx-proxy.yml +++ b/roles/jenkins-php-v1/tasks/60_install-nginx-proxy.yml @@ -43,7 +43,7 @@ value: '"--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"' no_extra_spaces: yes register: tmp - notify: restart jenkins + notify: system restart jenkins and wait - name: Etckeeper - commit command: "etckeeper commit 'Ansible/jenkins: maintaining /etc/default/jenkins'" when: tmp.changed and etckeeper_installed diff --git a/roles/jenkins-php-v1/tasks/include_restartandwait.yml b/roles/jenkins-php-v1/tasks/include_restartandwait.yml new file mode 100644 index 0000000..eaa713f --- /dev/null +++ b/roles/jenkins-php-v1/tasks/include_restartandwait.yml @@ -0,0 +1,16 @@ +--- + +- name: system-restart jenkins and wait (include) + block: + - name: restart jenkins + service: name=jenkins state=restarted + - name: Loop until Jenkins is available + get_url: + url: "http://localhost:8080/login" + dest: "/dev/null" + force: True + register: result + until: result.status_code is defined and result.status_code == 200 + retries: 100 + delay: 5 + changed_when: False