2 # -*- coding: utf-8 -*-
7 Copyright (c) 2014 Frédéric Massart - FMCorz.net
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 http://github.com/FMCorz/mdk
26 from jenkinsapi
import jenkins
27 from jenkinsapi
.custom_exceptions
import JenkinsAPIException
, TimeOut
28 from .config
import Conf
34 """Wrapper for Jenkins"""
40 def __init__(self
, url
=None, token
=None, load
=True):
41 self
.url
= url
or C
.get('ci.url')
42 self
.token
= token
or C
.get('ci.token')
48 """The Jenkins object"""
52 """Loads the Jenkins object"""
54 # Resets the logging level.
55 logger
= logging
.getLogger('jenkinsapi.job')
56 logger
.setLevel(logging
.WARNING
)
57 logger
= logging
.getLogger('jenkinsapi.build')
58 logger
.setLevel(logging
.WARNING
)
60 # Loads the jenkins object.
61 self
._jenkins
= jenkins
.Jenkins(self
.url
)
63 def precheckRemoteBranch(self
, remote
, branch
, integrateto
, issue
=None):
64 """Runs the precheck job and returns the build object"""
68 'integrateto': integrateto
71 params
['issue'] = issue
73 job
= self
.jenkins
.get_job('Precheck remote branch')
76 invoke
= job
.invoke(build_params
=params
, securitytoken
=self
.token
, invoke_pre_check_delay
=0)
77 invoke
.block_until_not_queued(60, 2)
78 except JenkinsAPIException
:
79 raise CIException('Failed to invoke the build, check your permissions.')
81 raise CIException('The build has been in queue for more than 60s. Aborting, please refer to: %s' % job
.baseurl
)
83 build
= invoke
.get_build()
87 class CIException(Exception):