Fix wait for jenkins startup and plugin install for no-auth jenkins
diff --git a/jenkins/master/plugin.sls b/jenkins/master/plugin.sls
index 7eb8403..f260045 100644
--- a/jenkins/master/plugin.sls
+++ b/jenkins/master/plugin.sls
@@ -8,19 +8,23 @@
setup_jenkins_cli:
cmd.run:
- names:
- - sleep 30
- wget http://localhost:{{ master.http.port }}/jnlpJars/jenkins-cli.jar
- unless: "[ -f /root/jenkins-cli.jar ]"
- cwd: /root
+ - require:
+ - cmd: jenkins_service_running
{%- for plugin in master.plugins %}
install_jenkins_plugin_{{ plugin.name }}:
cmd.run:
- - name: java -jar jenkins-cli.jar -s http://localhost:{{ master.http.port }} install-plugin --username admin --password {{ master.user.admin.password }} {{ plugin.name }}
+ - name: >
+ java -jar jenkins-cli.jar -s http://localhost:{{ master.http.port }} install-plugin {{ plugin.name }} ||
+ java -jar jenkins-cli.jar -s http://localhost:{{ master.http.port }} install-plugin --username admin --password {{ master.user.admin.password }} {{ plugin.name }}
- unless: "[ -d {{ master.home }}/plugins/{{ plugin.name }} ]"
- cwd: /root
- require:
- cmd: setup_jenkins_cli
+ - cmd: jenkins_service_running
{%- endfor %}
diff --git a/jenkins/master/service.sls b/jenkins/master/service.sls
index 5baa7fe..d0925cb 100644
--- a/jenkins/master/service.sls
+++ b/jenkins/master/service.sls
@@ -99,4 +99,10 @@
- file: jenkins_{{ master.config }}
- file: {{ master.home }}/hudson.model.UpdateCenter.xml
+jenkins_service_running:
+ cmd.wait:
+ - name: "i=0; while true; do curl -s -f http://localhost:{{ master.http.port }} >/dev/null && exit 0; [ $i -gt 60 ] && exit 1; sleep 5; done"
+ - watch:
+ - service: jenkins_master_service
+
{%- endif %}