Commit 6ad6ba22 authored by Corentin Hermet's avatar Corentin Hermet

Initial commit

parents
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.12 (C:\Program Files\Python_2.7\python.exe)" project-jdk-type="Python SDK" />
<component name="SvnBranchConfigurationManager">
<option name="mySupportsUserInfoFilter" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/jenkins_cli_tool.iml" filepath="$PROJECT_DIR$/.idea/jenkins_cli_tool.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="svn" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
jenkins_cli_tool
================
.. image:: https://img.shields.io/pypi/v/jenkins_cli_tool.svg
:target: https://pypi.python.org/pypi/jenkins_cli_tool
:alt: Latest PyPI version
.. image:: False.png
:target: False
:alt: Latest Travis CI build status
Jenkins CLI Tool
Usage
-----
Installation
------------
Requirements
^^^^^^^^^^^^
Compatibility
-------------
Licence
-------
Authors
-------
`jenkins_cli_tool` was written by `Corentin Hermet <chermet@axway.com>`_.
import click
class Car:
def __init__(self):
self.speed = 0
self.odometer = 0
self.time = 0
def say_state(self):
print("I'm going {} kph!".format(self.speed))
def accelerate(self):
self.speed += 5
def brake(self):
self.speed -= 5
def step(self):
self.odometer += self.speed
self.time += 1
def average_speed(self):
return self.odometer / self.time
if __name__ == '__main__':
my_car = Car()
print("I'm a car!")
while True:
action = raw_input("What should I do? [A]ccelerate, [B]rake, "
"show [O]dometer, or show average [S]peed?").upper()
if action not in "ABOS" or len(action) != 1:
print("I don't know how to do that")
continue
if action == 'A':
my_car.accelerate()
elif action == 'B':
my_car.brake()
elif action == 'O':
print("The car has driven {} kilometers".format(my_car.odometer))
elif action == 'S':
print("The car's average speed was {} kph".format(my_car.average_speed()))
my_car.step()
my_car.say_state()
\ No newline at end of file
import click
@click.command()
@click.option('--count', default=1, help='number of greetings')
@click.argument('name')
@click.argument('lol')
def hello(count, name, lol):
count=3
for x in range(count):
click.echo('Hello %s %s!' %(name , lol) )
if __name__ == '__main__':
hello()
import jenkins
import pprint
import click
@click.group()
@click.option('--job_name', help='Jenkins job name.', prompt=True)
def start():
global server
server = jenkins.Jenkins('http://jenkins-qa.lab.dubl.axway.int:8080', username='chermet', password='Shadow1995!!!')
@start.command()
@click.option('--job_name', help='Jenkins job name.', prompt=True)
def startJob(job_name):
server.build_job(job_name,parameters=None,token="62ebe5c65b3231d233ea1eaa106a642f")
#@click.option('--job_name', help='Jenkins job name.', prompt=True)
@start.command()
def jobExists(job_name):
return server.job_exists(job_name)
@click.group()
@click.option('--job_nameaa', help='Jenkinzeazeaze.', prompt=True)
def start2():
pass
@start2.command()
@click.option('--job_nameaa', help='Jenkinzeazeaze.', prompt=True)
def aa():
pass
cli = click.CommandCollection(sources=[start, start2])
if __name__ == '__main__':
cli()
"""jenkins_cli_tool - Jenkins CLI Tool"""
__version__ = '0.1.0'
__author__ = 'Corentin Hermet <chermet@axway.com>'
__all__ = []
import jenkins
import pprint
import click
@click.group()
def cli():
global server
server = jenkins.Jenkins('http://jenkins-qa.lab.dubl.axway.int:8080', username='chermet', password='Shadow1995!!!')
@cli.command()
def sync():
print('Synching')
if __name__ == '__main__':
cli()
\ No newline at end of file
import jenkins
import pprint
if __name__ == '__main__':
server = jenkins.Jenkins('http://jenkins-qa.lab.dubl.axway.int:8080', username='chermet', password='Shadow1995!!!')
print('User: %s' %(server.get_whoami()['fullName']))
jobs = server.get_all_jobs(3)
for job in jobs:
print job['name']
job_status = server.get_job_info("JenkinsCLITest-Corentin")
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(job_status)
print job_status['url']
from distutils.command import build
import jenkins
import pprint
import click
from time import sleep
import sys
import getopt
import ast
pp = pprint.PrettyPrinter(indent=4)
def startJob(jobName, login, pwd, server, port,parameters, wait):
server = jenkins.Jenkins('http://' + server + ':' + port, username=login, password=pwd)
try:
next_build_number = server.get_job_info(jobName)['nextBuildNumber']
except jenkins.NotFoundException:
print "NotFoundException when looking for job with name '%s'." % jobName
exit(1)
except:
print "Unexpected error:", sys.exc_info()[0]
raise
print "Starting %s , build #%s." % (jobName, next_build_number)
try:
server.build_job("JenkinsCLITest-Corentin", parameters, token=None)
except:
pp.pprint(sys.exc_info())
print "Please verify your parameters (especially choice parameters - are the values chosen authorized?"
exit(2)
stop = False
while not stop:
try:
build_info = server.get_build_info(jobName, next_build_number)
except jenkins.NotFoundException:
print "NotFoundException when looking for build #%s : build probably still in the queue. Waiting %d sc until next retry." % (next_build_number, wait)
sleep(wait)
pass
except:
print "Unexpected error:", sys.exc_info()[0]
raise
else:
if build_info['result'] == 'SUCCESS':
print "Build #%s finished with result : SUCCESS." % next_build_number
exit(0)
elif build_info['result'] == 'FAILED':
print "Build #%s finished with result : FAILED." % next_build_number
stop = True
exit(3)
elif build_info['result'] == None and build_info['building'] == True:
print "Build #%s is not finished yet. Waiting %d sc until next check." % (next_build_number,wait)
sleep(wait)
else:
print "Unknown build result. Full trace below:"
pp.pprint(build_info)
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:],
"",
["login=","pwd=","server=","port=","jobName=","parameters=","wait=","default","help"])
except getopt.GetoptError:
print "Incorrect arguments."
sys.exit(2)
for opt, arg in opts:
if opt in ("--login"):
login = arg
elif opt in ("--pwd"):
pwd = arg
elif opt in ("--server"):
server = arg
elif opt in ("--port"):
port = arg
elif opt in ("--jobName"):
jobName = arg
elif opt in ("--parameters"):
parameters = ast.literal_eval(arg)
elif opt in ("--wait"):
wait = int(arg)
elif opt in ("--help"):
print ("Usage: python startJob \n"
"--login <login>\n"
"--pwd <pwd>\n"
"--server <server>\n"
"--port <port>\n"
"--jobName <jobName>\n"
"--parameters \"{'XXXX':'YYYY', ...}\"\n"
"--wait <time to wait between each retry to check for build status>\n"
"--help\n"
"--default")
exit(0)
elif opt in ("--default"):
login = "chermet"
pwd = "Shadow1995!!!"
server = "jenkins-qa.lab.dubl.axway.int"
port = "8080"
jobName = "JenkinsCLITest-Corentin"
parameters = {'THREADS': 'AAAA', 'IDK': 'value2'}
wait = 5
startJob(jobName, login, pwd, server, port, parameters,wait)
#--login chermet --pwd Shadow1995!!! --server jenkins-qa.lab.dubl.axway.int --port 8080 --jobName JenkinsCLITest-Corentin --parameters "{'THREADS': 'AAAA', 'IDK': 'value2'}"
#--login chermet --pwd Shadow1995!!! --default
\ No newline at end of file
import click
@click.group()
@click.option('debug/no-debug')
def cli(debug):
click.echo('Debug mode is %s' % ('on' if debug else 'off'))
@cli.command()
def sync():
click.echo('Synching')
@cli.command()
def blah():
click.echo('blah')
if __name__ == '__main__':
cli()
# setup.cfg
[bdist_wheel]
# univesal wheel
universal=1
\ No newline at end of file
import setuptools
setuptools.setup(
name="jenkins_cli_tool",
version="0.1.0",
url="TBD",
author="Corentin Hermet",
author_email="chermet@axway.com",
description="Jenkins CLI Tool",
long_description=open('README.rst').read(),
packages=setuptools.find_packages(),
install_requires=[],
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
],
)
# Sample Test passing with nose and pytest
def test_pass():
assert True, "dummy sample test"
[tox]
envlist=py27,py34,py35
[testenv]
commands=py.test jenkins_cli_tool
deps=pytest
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment