├── tests ├── __init__.py └── test_jenkins.py ├── setup.cfg ├── requirements.txt ├── JenkinsLibrary ├── version.py ├── __init__.py └── jenkins_face.py ├── README.md ├── .gitignore ├── generate.py ├── .travis.yml ├── License.md ├── setup.py ├── Makefile └── docs └── JenkinsLibrary.html /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | robotframework -------------------------------------------------------------------------------- /JenkinsLibrary/version.py: -------------------------------------------------------------------------------- 1 | VERSION = '0.7.4' 2 | -------------------------------------------------------------------------------- /JenkinsLibrary/__init__.py: -------------------------------------------------------------------------------- 1 | from .jenkins_face import JenkinsFace 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # robotframework-jenkinslibrary 2 | Jenkins wrapper library for robotframework 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | dist 3 | .idea 4 | .cache 5 | .coverage 6 | *egg* 7 | build 8 | htmlcov 9 | result -------------------------------------------------------------------------------- /generate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os.path import join, dirname 3 | from robot.libdoc import libdoc 4 | 5 | 6 | def main(): 7 | libdoc(join(dirname(__file__), 'JenkinsLibrary'), join(dirname(__file__), 'docs', 'JenkinsLibrary.html')) 8 | 9 | 10 | if __name__ == '__main__': 11 | main() 12 | -------------------------------------------------------------------------------- /tests/test_jenkins.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from JenkinsLibrary.jenkins_face import JenkinsFace 3 | 4 | 5 | class JenkinsSessionTest(unittest.TestCase): 6 | 7 | def setUp(self) -> None: 8 | self.jenkins = JenkinsFace() 9 | 10 | def test_delete_snapshot_with_delete_key(self): 11 | self.jenkins.create_session_jenkins('a', 'a', 'a', 'a') 12 | self.assertIsNotNone(self.jenkins._session) 13 | 14 | if __name__ == '__main__': 15 | unittest.main() 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | language: python 3 | python: 4 | - '3.7' 5 | install: pip install -r requirements.txt 6 | script: make clean docs dist 7 | deploy: 8 | provider: pypi 9 | user: __token__ 10 | password: 11 | secure: LnRMKO1yXkg0ad3jPKxVHKThhwoT7H5/wOrytCIcs2l+/WqiJ4qjModrYwjciU9hEtnCwtKKVUWlFGbIHASgihqFeqQruSHgWENPxh1zx0zexD8j/sasqo9eqTX+oHvQzjyr+U1YNBhvLakWbfvFSx4siMrgFWGnoGjjM523b3Ap5X4uZ6N16zWe3uby/7Bz0lcsAvbnqtoVxbAZSMsM+oGIcVTio+dd1etWl5axyybXMNlG52zcZh9BZ/ZotgSPuuGb29W68fL25L/bqytdw8rif0vydMmmTOjjQy1sJ9pDPZwbtJ4fyi6T3zIToML9D/MG7nULHvV1L2rd4hSkNLK/NbKBcitr1Gu69xL6FxvmoJygJzuj/6EQmww8tOSIr2accDhXNobsnS/cP3Bf8YMRwqftBGH5xWqYzd7vT/vv/bcISbRYm4ugnYMO7AfFyZCKNVp5bsNxQ4P9IqzX93EgsBvKdySl1Juo9yiy8F5RvAOgJt2++7JBXkvX32xN3u2BTkGyCQM/lTWwkGJ/s5j0HA/2YNO9mPJNMgO9ZAxxK/zPSNOf44Oi7Gcd7OJhytoV503Uo15HA8RaamOnlve/edup0NzeJMmI/SEkyhEW/yUViLcijYZACHCMydTC5XO71chk0tegcZbJpdEpeSXqCrqfTiaoxieCT6fMeTw= 12 | on: 13 | tags: true 14 | branch: master 15 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 robotframework-jenkinslibrary 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | import re 3 | 4 | # Read version from file without loading the module 5 | with open('JenkinsLibrary/version.py', 'r') as version_file: 6 | version_match = re.search(r"^VERSION ?= ?['\"]([^'\"]*)['\"]", version_file.read(), re.M) 7 | 8 | with open("README.md", "r") as fh: 9 | long_description = fh.read() 10 | 11 | if version_match: 12 | VERSION = version_match.group(1) 13 | else: 14 | VERSION = '0.1' 15 | 16 | REQUIREMENTS = [ 17 | 'requests' 18 | ] 19 | 20 | TEST_REQUIREMENTS = [ 21 | 'coverage', 'wheel', 'pytest' 22 | ] 23 | 24 | CLASSIFIERS = [ 25 | "Development Status :: 3 - Alpha", 26 | "Intended Audience :: Developers", 27 | "Topic :: Software Development :: Testing", 28 | "License :: OSI Approved :: MIT License", 29 | "Programming Language :: Python :: 3", 30 | "Operating System :: OS Independent", 31 | "Programming Language :: Python", 32 | # "Programming Language :: Python :: 2", 33 | # "Programming Language :: Python :: 2.7", 34 | "Programming Language :: Python :: 3", 35 | "Programming Language :: Python :: 3.5", 36 | "Programming Language :: Python :: 3.6", 37 | "Programming Language :: Python :: 3.7", 38 | ] 39 | 40 | setup( 41 | name="robotframework-jenkinslibrary", 42 | version=VERSION, 43 | author="Panchorn Lertvipada", 44 | author_email="nonpcn@gmail.com", 45 | description="Jenkins wrapper library for robotframework", 46 | url="https://github.com/Panchorn/robotframework-jenkinslibrary.git", 47 | license="MIT", 48 | packages=find_packages(), 49 | package_dir={'robotframework-jenkinslibrary': 'JenkinsLibrary'}, 50 | install_requires=REQUIREMENTS, 51 | tests_require=TEST_REQUIREMENTS, 52 | classifiers=CLASSIFIERS 53 | ) 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean clean-test clean-pyc clean-build docs help 2 | .DEFAULT_GOAL := help 3 | define BROWSER_PYSCRIPT 4 | import os, webbrowser, sys 5 | try: 6 | from urllib import pathname2url 7 | except: 8 | from urllib.request import pathname2url 9 | 10 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) 11 | endef 12 | export BROWSER_PYSCRIPT 13 | 14 | define PRINT_HELP_PYSCRIPT 15 | import re, sys 16 | 17 | for line in sys.stdin: 18 | match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) 19 | if match: 20 | target, help = match.groups() 21 | print("%-20s %s" % (target, help)) 22 | endef 23 | export PRINT_HELP_PYSCRIPT 24 | BROWSER := python -c "$$BROWSER_PYSCRIPT" 25 | 26 | help: 27 | @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) 28 | 29 | clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts 30 | 31 | 32 | clean-build: ## remove build artifacts 33 | rm -fr build/ 34 | rm -fr dist/ 35 | rm -fr .eggs/ 36 | find . -name '*.egg-info' -exec rm -fr {} + 37 | find . -name '*.egg' -exec rm -f {} + 38 | 39 | clean-pyc: ## remove Python file artifacts 40 | find . -name '*.pyc' -exec rm -f {} + 41 | find . -name '*.pyo' -exec rm -f {} + 42 | find . -name '*~' -exec rm -f {} + 43 | find . -name '__pycache__' -exec rm -fr {} + 44 | 45 | clean-test: ## remove test and coverage artifacts 46 | rm -fr .tox/ 47 | rm -f .coverage 48 | rm -fr htmlcov/ 49 | 50 | test: ## run tests quickly with the default Python 51 | python setup.py test 52 | 53 | coverage: ## check code coverage quickly with the default Python 54 | coverage run --source JenkinsLibrary setup.py test 55 | coverage report -m 56 | coverage html 57 | 58 | docs: ## generate Sphinx HTML documentation, including API docs 59 | rm -f docs/robotframework-jenkinslibrary.rst 60 | rm -f docs/modules.rst 61 | python generate.py 62 | 63 | release: clean ## package and upload a release 64 | python setup.py sdist upload 65 | python setup.py bdist_wheel upload 66 | 67 | dist: clean ## builds source and wheel package 68 | python setup.py sdist 69 | python setup.py bdist_wheel 70 | ls -l dist 71 | 72 | install: clean test coverage docs ## install the package to the active Python's site-packages 73 | python setup.py install -------------------------------------------------------------------------------- /JenkinsLibrary/jenkins_face.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import urllib3 4 | 5 | BASE_ENDPOINT = '{}://{}:{}@{}/' 6 | GET_JOB = '{}/api/json' 7 | GET_JOB_BUILD = '{}/{}/api/json' 8 | BUILD_JOB_WITH_PARAMETERS = '{}/buildWithParameters' 9 | 10 | 11 | class JenkinsFace(object): 12 | 13 | def __init__(self): 14 | self._endpoint = None 15 | self._session = None 16 | self._settings = None 17 | 18 | def create_session_jenkins(self, 19 | protocol='https', 20 | url=None, 21 | username=None, 22 | password=None, 23 | verify=False): 24 | if not verify: 25 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) 26 | self._endpoint = BASE_ENDPOINT.format(protocol, username, password, url) 27 | self._session = requests.Session() 28 | self._settings = self._session.merge_environment_settings( 29 | self._endpoint, {}, None, verify, None 30 | ) 31 | self._settings['allow_redirects'] = False 32 | 33 | def get_jenkins_job(self, name=None): 34 | if not name: 35 | raise Exception('Job name should not be None') 36 | req = self._session.prepare_request( 37 | requests.Request( 38 | 'GET', 39 | self._job_url(GET_JOB, [name]) 40 | ) 41 | ) 42 | return self._get_response( 43 | self._send(req) 44 | ) 45 | 46 | def get_jenkins_job_build(self, name=None, build_number='lastBuild'): 47 | if not name: 48 | raise Exception('Job name should not be None') 49 | req = self._session.prepare_request( 50 | requests.Request( 51 | 'GET', 52 | self._job_url(GET_JOB_BUILD, [name, build_number]) 53 | ) 54 | ) 55 | return self._get_response( 56 | self._send(req) 57 | ) 58 | 59 | def build_jenkins_with_parameters(self, name=None, data=None): 60 | if not name: 61 | raise Exception('Job name should not be None') 62 | job_detail = self.get_jenkins_job(name) 63 | req = self._session.prepare_request( 64 | requests.Request( 65 | 'POST', 66 | self._job_url(BUILD_JOB_WITH_PARAMETERS, [name]), 67 | data=data 68 | ) 69 | ) 70 | response = self._send(req) 71 | response.raise_for_status() 72 | return job_detail['nextBuildNumber'] 73 | 74 | def _send(self, req): 75 | return self._session.send(req, **self._settings) 76 | 77 | @staticmethod 78 | def _get_response(response): 79 | response.raise_for_status() 80 | return json.loads(response.content, encoding='utf-8') 81 | 82 | def _job_url(self, url_format, params): 83 | url = url_format.format(*params) 84 | return self._endpoint + url 85 | -------------------------------------------------------------------------------- /docs/JenkinsLibrary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 160 | 230 | 243 | 266 | 317 | 520 | 524 | 536 | 549 | 552 |