Jenkins Remote Access API
Https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
If you use Python to manipulate control Jenkins, there are two module can be used, JENKINSAPI and python-jenkins.
Jenkinsapi:https://pypi.python.org/pypi/jenkinsapi
python-jenkins:https://pypi.python.org/pypi/python-jenkins/
Python-jenkins online Documentation: http://python-jenkins.readthedocs.io/en/latest/api.html
Examples are as follows:
Import Jenkins
import time
import sys
def run ():
server = Jenkins. Jenkins (Url=url, Username=user, password=pwd)
server.build_job (Name=jobname, Token=jobtoken) while
True:
time.sleep (1)
print ' Check running job ... '
If Len (Server.get_running_builds ()) = = 0:
break else:
time.sleep (m)
Last_build_number = Server.get_job_info (jobName) [' Lastcompletedbuild '] [' number ']
build_info = Server.get_build_info (JobName, last_build_number)
Build_result = build_info[' result ']
print ' Build and result is ' + build_result
if Build_result = ' SUCCESS ':
sys.exit (0)
else:
sys.exit (-1
if __name__ = = ' __main__ ':
run ()
Description
1. Establish Jenkins Links
2. Remotely triggers a job above the Jenkins
3. Detection job is build complete, if completed, check build result