I'm trying to restart the Jenkins service using Ansible:
- name: Restart Jenkins to make the plugin data available service: name=jenkins state=restarted - name: Wait for Jenkins to restart wait_for: host=localhost port=8080 delay=20 timeout=300 - name: Install Jenkins plugins command: java -jar {{ jenkins_cli_jar }} -s {{ jenkins_dashboard_url }} install-plugin {{ item }} creates=/var/lib/jenkins/plugins/{{ item }}.jpi with_items: jenkins_plugins
But on the first run, the third task throws lots of Java errors including this: Suppressed: java.io.IOException: Server returned HTTP response code: 503 for URL
, which makes me think the web server (handled entirely by Jenkins) wasn't ready. Sometimes when I go to the Jenkins dashboard using my browser it says that Jenkins isn't ready and that it will reload when it is, and it does, it works fine. But I'm not sure if accessing the page is what starts the server, or what.
So I guess what I need is to curl many times until the http code is 200? Is there any other way?
Either way, how do I do that?
How do you normally restart Jenkins?
I also restarted the Jenkins service and it worked. It did take 3-4 minutes after I restarted the service for the page to load up, though. So make sure you're patient before moving on to something else.
Using url <jenkins_url>/safeRestart – Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete. <jenkins_url>/restart – Forces a restart without waiting for builds to complete.
Using the URI module http://docs.ansible.com/ansible/uri_module.html
- name: "wait for ABC to come up" uri: url: "http://127.0.0.1:8080/ABC" status_code: 200 register: result until: result.status == 200 retries: 60 delay: 1
I solved it using curl + Ansible's until
, which I just learned about. It will request the page until the http status code is 200 OK.
- name: Wait untils Jenkins web API is available shell: curl --head --silent http://localhost:8080/cli/ register: result until: result.stdout.find("200 OK") != -1 retries: 12 delay: 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With