-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-jekins-log.py
executable file
·58 lines (50 loc) · 1.94 KB
/
get-jekins-log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# build-req.py --- Description
#
# Copyright (C) 2021, Schspa, all rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# refs: https://python-jenkins.readthedocs.io/en/latest/examples.html#example-3-working-with-jenkins-jobs
import jenkins
import getpass
import sys
import click
def get_build_output(server, build_name, build_number):
logs = server.get_build_console_output(build_name, build_number)
return logs
@click.command()
@click.option('-r', '--url', default='http://ci.athion.net')
@click.option('-u', '--username', default=None)
@click.option('-p', '--password', default=None)
@click.option('-b', '--buildname')
@click.option('-n', '--buildnumber', default=None, type=int)
@click.option('--verbose', is_flag=True)
def get_jekins_log(url, username, password, buildname, buildnumber, verbose):
"""Create a new jekins build and wait for build exit with status"""
if username is None:
username = getpass.getuser()
if password is None:
password = getpass.getpass()
elif password == "-":
password = sys.stdin.read().strip()
pass
server = jenkins.Jenkins(url, username=username, password=password)
logs = get_build_output(server, buildname, buildnumber)
print(logs)
sys.exit(0)
if __name__ == '__main__':
get_jekins_log()