raise JenkinsJobsException instead of Exception
Normalize all exceptions to be JenkinsJobsException from the jenkins_jobs.errors module. This patch replace all occurences of the build-in Exception. Change-Id: I923ec35467dd93211d8cd1e6c69c0321d9391ec8
This commit is contained in:
parent
0b180a6ade
commit
1e2ae253f2
@ -39,6 +39,7 @@ Example::
|
|||||||
|
|
||||||
import xml.etree.ElementTree as XML
|
import xml.etree.ElementTree as XML
|
||||||
import jenkins_jobs.modules.base
|
import jenkins_jobs.modules.base
|
||||||
|
from jenkins_jobs.errors import JenkinsJobsException
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -139,10 +140,10 @@ def copyartifact(parser, xml_parent, data):
|
|||||||
'workspace-latest': 'WorkspaceSelector',
|
'workspace-latest': 'WorkspaceSelector',
|
||||||
'build-param': 'ParameterizedBuildSelector'}
|
'build-param': 'ParameterizedBuildSelector'}
|
||||||
if select not in selectdict:
|
if select not in selectdict:
|
||||||
raise Exception("which-build entered is not valid must be one of: " +
|
raise JenkinsJobsException("which-build entered is not valid must be "
|
||||||
"last-successful, specific-build, last-saved, " +
|
"one of: last-successful, specific-build, "
|
||||||
"upstream-build, permalink, workspace-latest, " +
|
"last-saved, upstream-build, permalink, "
|
||||||
" or build-param")
|
"workspace-latest, or build-param")
|
||||||
permalink = data.get('permalink', 'last')
|
permalink = data.get('permalink', 'last')
|
||||||
permalinkdict = {'last': 'lastBuild',
|
permalinkdict = {'last': 'lastBuild',
|
||||||
'last-stable': 'lastStableBuild',
|
'last-stable': 'lastStableBuild',
|
||||||
@ -151,8 +152,9 @@ def copyartifact(parser, xml_parent, data):
|
|||||||
'last-unstable': 'lastUnstableBuild',
|
'last-unstable': 'lastUnstableBuild',
|
||||||
'last-unsuccessful': 'lastUnsuccessfulBuild'}
|
'last-unsuccessful': 'lastUnsuccessfulBuild'}
|
||||||
if permalink not in permalinkdict:
|
if permalink not in permalinkdict:
|
||||||
raise Exception("permalink entered is not valid must be one of: " +
|
raise JenkinsJobsException("permalink entered is not valid must be "
|
||||||
"last, last-stable, last-successful, last-failed, " +
|
"one of: last, last-stable, "
|
||||||
|
"last-successful, last-failed, "
|
||||||
"last-unstable, or last-unsuccessful")
|
"last-unstable, or last-unsuccessful")
|
||||||
selector = XML.SubElement(t, 'selector',
|
selector = XML.SubElement(t, 'selector',
|
||||||
{'class': 'hudson.plugins.copyartifact.' +
|
{'class': 'hudson.plugins.copyartifact.' +
|
||||||
|
@ -34,6 +34,7 @@ Example::
|
|||||||
|
|
||||||
import xml.etree.ElementTree as XML
|
import xml.etree.ElementTree as XML
|
||||||
import jenkins_jobs.modules.base
|
import jenkins_jobs.modules.base
|
||||||
|
from jenkins_jobs.errors import JenkinsJobsException
|
||||||
|
|
||||||
|
|
||||||
def ownership(parser, xml_parent, data):
|
def ownership(parser, xml_parent, data):
|
||||||
@ -351,8 +352,9 @@ def extended_choice(parser, xml_parent, data):
|
|||||||
'radio': 'PT_RADIO',
|
'radio': 'PT_RADIO',
|
||||||
'checkbox': 'PT_CHECKBOX'}
|
'checkbox': 'PT_CHECKBOX'}
|
||||||
if choice not in choicedict:
|
if choice not in choicedict:
|
||||||
raise Exception("Type entered is not valid, must be one of: " +
|
raise JenkinsJobsException("Type entered is not valid, must be one "
|
||||||
"single-select, multi-select, radio, or checkbox")
|
"of: single-select, multi-select, radio, "
|
||||||
|
"or checkbox")
|
||||||
XML.SubElement(extended, 'type').text = choicedict[choice]
|
XML.SubElement(extended, 'type').text = choicedict[choice]
|
||||||
XML.SubElement(extended, 'value').text = data.get('value', '')
|
XML.SubElement(extended, 'value').text = data.get('value', '')
|
||||||
XML.SubElement(extended, 'propertyFile').text = data.get('property-file',
|
XML.SubElement(extended, 'propertyFile').text = data.get('property-file',
|
||||||
@ -417,9 +419,9 @@ def build_blocker(parser, xml_parent, data):
|
|||||||
'hudson.plugins.'
|
'hudson.plugins.'
|
||||||
'buildblocker.BuildBlockerProperty')
|
'buildblocker.BuildBlockerProperty')
|
||||||
if data is None or 'blocking-jobs' not in data:
|
if data is None or 'blocking-jobs' not in data:
|
||||||
raise Exception('blocking-jobs field is missing')
|
raise JenkinsJobsException('blocking-jobs field is missing')
|
||||||
elif data.get('blocking-jobs', None) is None:
|
elif data.get('blocking-jobs', None) is None:
|
||||||
raise Exception('blocking-jobs list must not be empty')
|
raise JenkinsJobsException('blocking-jobs list must not be empty')
|
||||||
XML.SubElement(blocker, 'useBuildBlocker').text = str(
|
XML.SubElement(blocker, 'useBuildBlocker').text = str(
|
||||||
data.get('use-build-blocker', True)).lower()
|
data.get('use-build-blocker', True)).lower()
|
||||||
jobs = ''
|
jobs = ''
|
||||||
|
@ -26,6 +26,7 @@ the build is complete.
|
|||||||
|
|
||||||
import xml.etree.ElementTree as XML
|
import xml.etree.ElementTree as XML
|
||||||
import jenkins_jobs.modules.base
|
import jenkins_jobs.modules.base
|
||||||
|
from jenkins_jobs.errors import JenkinsJobsException
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
@ -237,7 +238,7 @@ def trigger(parser, xml_parent, data):
|
|||||||
|
|
||||||
threshold = data.get('threshold', 'SUCCESS')
|
threshold = data.get('threshold', 'SUCCESS')
|
||||||
if threshold not in thresholds.keys():
|
if threshold not in thresholds.keys():
|
||||||
raise Exception("threshold must be one of " +
|
raise JenkinsJobsException("threshold must be one of %s" %
|
||||||
", ".join(threshold.keys()))
|
", ".join(threshold.keys()))
|
||||||
tname = XML.SubElement(tthreshold, 'name')
|
tname = XML.SubElement(tthreshold, 'name')
|
||||||
tname.text = threshold
|
tname.text = threshold
|
||||||
@ -498,8 +499,8 @@ def jacoco(parser, xml_parent, data):
|
|||||||
for item in data['targets']:
|
for item in data['targets']:
|
||||||
item_name = item.keys()[0]
|
item_name = item.keys()[0]
|
||||||
if item_name not in itemsList:
|
if item_name not in itemsList:
|
||||||
raise Exception("item entered is not valid must be one " +
|
raise JenkinsJobsException("item entered is not valid must be "
|
||||||
"of: " + ",".join(itemsList))
|
"one of: %s" % ",".join(itemsList))
|
||||||
item_values = item.get(item_name, 0)
|
item_values = item.get(item_name, 0)
|
||||||
|
|
||||||
XML.SubElement(jacoco,
|
XML.SubElement(jacoco,
|
||||||
@ -1765,8 +1766,9 @@ def jabber(parser, xml_parent, data):
|
|||||||
'failure-fixed': 'FAILURE_AND_FIXED',
|
'failure-fixed': 'FAILURE_AND_FIXED',
|
||||||
'change': 'STATECHANGE_ONLY'}
|
'change': 'STATECHANGE_ONLY'}
|
||||||
if strategy not in strategydict:
|
if strategy not in strategydict:
|
||||||
raise Exception("Strategy entered is not valid, must be one of: " +
|
raise JenkinsJobsException("Strategy entered is not valid, must be " +
|
||||||
"all, failure, failure-fixed, or change")
|
"one of: all, failure, failure-fixed, or "
|
||||||
|
"change")
|
||||||
XML.SubElement(j, 'strategy').text = strategydict[strategy]
|
XML.SubElement(j, 'strategy').text = strategydict[strategy]
|
||||||
XML.SubElement(j, 'notifyOnBuildStart').text = str(
|
XML.SubElement(j, 'notifyOnBuildStart').text = str(
|
||||||
data.get('notify-on-build-start', False)).lower()
|
data.get('notify-on-build-start', False)).lower()
|
||||||
@ -1784,9 +1786,9 @@ def jabber(parser, xml_parent, data):
|
|||||||
'summary-build': 'BuildParametersBuildToChatNotifier',
|
'summary-build': 'BuildParametersBuildToChatNotifier',
|
||||||
'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
|
'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
|
||||||
if message not in messagedict:
|
if message not in messagedict:
|
||||||
raise Exception("Message entered is not valid, must be one of: " +
|
raise JenkinsJobsException("Message entered is not valid, must be one "
|
||||||
"summary-scm, summary, summary-build " +
|
"of: summary-scm, summary, summary-build "
|
||||||
"of summary-scm-fail")
|
"or summary-scm-fail")
|
||||||
XML.SubElement(j, 'buildToChatNotifier', {
|
XML.SubElement(j, 'buildToChatNotifier', {
|
||||||
'class': 'hudson.plugins.im.build_notify.' + messagedict[message]})
|
'class': 'hudson.plugins.im.build_notify.' + messagedict[message]})
|
||||||
XML.SubElement(j, 'matrixMultiplier').text = 'ONLY_CONFIGURATIONS'
|
XML.SubElement(j, 'matrixMultiplier').text = 'ONLY_CONFIGURATIONS'
|
||||||
@ -2348,8 +2350,9 @@ def warnings(parser, xml_parent, data):
|
|||||||
'all-priorities': 'low'}
|
'all-priorities': 'low'}
|
||||||
priority = data.get('health-priorities', 'all-priorities')
|
priority = data.get('health-priorities', 'all-priorities')
|
||||||
if priority not in prioritiesDict:
|
if priority not in prioritiesDict:
|
||||||
raise Exception("Health-Priority entered is not valid must be one " +
|
raise JenkinsJobsException("Health-Priority entered is not valid must "
|
||||||
"of: " + ",".join(prioritiesDict.keys()))
|
"be one of: %s" %
|
||||||
|
",".join(prioritiesDict.keys()))
|
||||||
XML.SubElement(warnings, 'thresholdLimit').text = prioritiesDict[priority]
|
XML.SubElement(warnings, 'thresholdLimit').text = prioritiesDict[priority]
|
||||||
td = XML.SubElement(warnings, 'thresholds')
|
td = XML.SubElement(warnings, 'thresholds')
|
||||||
for base in ["total", "new"]:
|
for base in ["total", "new"]:
|
||||||
@ -2496,8 +2499,9 @@ def ircbot(parser, xml_parent, data):
|
|||||||
'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
|
'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
|
||||||
message = data.get('message-type', 'summary-scm')
|
message = data.get('message-type', 'summary-scm')
|
||||||
if message not in message_dict:
|
if message not in message_dict:
|
||||||
raise Exception("message-type entered is not valid, must be one of: " +
|
raise JenkinsJobsException("message-type entered is not valid, must "
|
||||||
"%s" % ", ".join(message_dict.keys()))
|
"be one of: %s" %
|
||||||
|
", ".join(message_dict.keys()))
|
||||||
message = "hudson.plugins.im.build_notify." + message_dict.get(message)
|
message = "hudson.plugins.im.build_notify." + message_dict.get(message)
|
||||||
XML.SubElement(top, 'buildToChatNotifier', attrib={'class': message})
|
XML.SubElement(top, 'buildToChatNotifier', attrib={'class': message})
|
||||||
strategy_dict = {'all': 'ALL',
|
strategy_dict = {'all': 'ALL',
|
||||||
@ -2507,7 +2511,8 @@ def ircbot(parser, xml_parent, data):
|
|||||||
'statechange-only': 'STATECHANGE_ONLY'}
|
'statechange-only': 'STATECHANGE_ONLY'}
|
||||||
strategy = data.get('strategy', 'all')
|
strategy = data.get('strategy', 'all')
|
||||||
if strategy not in strategy_dict:
|
if strategy not in strategy_dict:
|
||||||
raise Exception("strategy entered is not valid, must be one of: %s" %
|
raise JenkinsJobsException("strategy entered is not valid, must be "
|
||||||
|
"one of: %s" %
|
||||||
", ".join(strategy_dict.keys()))
|
", ".join(strategy_dict.keys()))
|
||||||
XML.SubElement(top, 'strategy').text = strategy_dict.get(strategy)
|
XML.SubElement(top, 'strategy').text = strategy_dict.get(strategy)
|
||||||
targets = XML.SubElement(top, 'targets')
|
targets = XML.SubElement(top, 'targets')
|
||||||
@ -2534,8 +2539,9 @@ def ircbot(parser, xml_parent, data):
|
|||||||
'only-parent': 'ONLY_PARENT'}
|
'only-parent': 'ONLY_PARENT'}
|
||||||
matrix = data.get('matrix-notifier', 'only_configurations')
|
matrix = data.get('matrix-notifier', 'only_configurations')
|
||||||
if matrix not in matrix_dict:
|
if matrix not in matrix_dict:
|
||||||
raise Exception("matrix-notifier entered is not valid, must be one " +
|
raise JenkinsJobsException("matrix-notifier entered is not valid, "
|
||||||
"of: %s" % ", ".join(matrix_dict.keys()))
|
"must be one of: %s" %
|
||||||
|
", ".join(matrix_dict.keys()))
|
||||||
XML.SubElement(top, 'matrixMultiplier').text = matrix_dict.get(matrix)
|
XML.SubElement(top, 'matrixMultiplier').text = matrix_dict.get(matrix)
|
||||||
|
|
||||||
|
|
||||||
@ -2656,8 +2662,8 @@ def plot(parser, xml_parent, data):
|
|||||||
for serie in series:
|
for serie in series:
|
||||||
format_data = serie.get('format')
|
format_data = serie.get('format')
|
||||||
if format_data not in format_dict:
|
if format_data not in format_dict:
|
||||||
raise Exception("format entered is not valid," +
|
raise JenkinsJobsException("format entered is not valid, must "
|
||||||
"must be one of:" +
|
"be one of: %s" %
|
||||||
" , ".join(format_dict.keys()))
|
" , ".join(format_dict.keys()))
|
||||||
subserie = XML.SubElement(topseries, format_dict.get(format_data))
|
subserie = XML.SubElement(topseries, format_dict.get(format_data))
|
||||||
XML.SubElement(subserie, 'file').text = serie.get('file')
|
XML.SubElement(subserie, 'file').text = serie.get('file')
|
||||||
@ -2666,9 +2672,10 @@ def plot(parser, xml_parent, data):
|
|||||||
if format_data == 'csv':
|
if format_data == 'csv':
|
||||||
inclusion_flag = serie.get('inclusion-flag', 'off')
|
inclusion_flag = serie.get('inclusion-flag', 'off')
|
||||||
if inclusion_flag not in inclusion_dict:
|
if inclusion_flag not in inclusion_dict:
|
||||||
raise Exception("Inclusion flag result entered is not " +
|
raise JenkinsJobsException("Inclusion flag result entered "
|
||||||
" valid, must be one of: " +
|
"is not valid, must be one of: "
|
||||||
", ".join(inclusion_dict))
|
"%s"
|
||||||
|
% ", ".join(inclusion_dict))
|
||||||
XML.SubElement(subserie, 'inclusionFlag').text = \
|
XML.SubElement(subserie, 'inclusionFlag').text = \
|
||||||
inclusion_dict.get(inclusion_flag)
|
inclusion_dict.get(inclusion_flag)
|
||||||
XML.SubElement(subserie, 'exclusionValues').text = \
|
XML.SubElement(subserie, 'exclusionValues').text = \
|
||||||
@ -2682,8 +2689,9 @@ def plot(parser, xml_parent, data):
|
|||||||
serie.get('xpath')
|
serie.get('xpath')
|
||||||
xpathtype = serie.get('xpath-type', 'node')
|
xpathtype = serie.get('xpath-type', 'node')
|
||||||
if xpathtype not in xpath_dict:
|
if xpathtype not in xpath_dict:
|
||||||
raise Exception("XPath result entered is not valid, must" +
|
raise JenkinsJobsException("XPath result entered is not "
|
||||||
" be one of: " + ", ".join(xpath_dict))
|
"valid, must be one of: %s" %
|
||||||
|
", ".join(xpath_dict))
|
||||||
XML.SubElement(subserie, 'nodeTypeString').text = \
|
XML.SubElement(subserie, 'nodeTypeString').text = \
|
||||||
xpath_dict.get(xpathtype)
|
xpath_dict.get(xpathtype)
|
||||||
XML.SubElement(subserie, 'fileType').text = serie.get('format')
|
XML.SubElement(subserie, 'fileType').text = serie.get('format')
|
||||||
@ -2695,8 +2703,8 @@ def plot(parser, xml_parent, data):
|
|||||||
'stackedbar', 'stackedbar3d', 'waterfall']
|
'stackedbar', 'stackedbar3d', 'waterfall']
|
||||||
style = plot.get('style', 'line')
|
style = plot.get('style', 'line')
|
||||||
if style not in style_list:
|
if style not in style_list:
|
||||||
raise Exception("style entered is not valid, must be one of: " +
|
raise JenkinsJobsException("style entered is not valid, must be "
|
||||||
", ".join(style_list))
|
"one of: %s" % ", ".join(style_list))
|
||||||
XML.SubElement(plugin, 'style').text = style
|
XML.SubElement(plugin, 'style').text = style
|
||||||
|
|
||||||
|
|
||||||
@ -2790,7 +2798,7 @@ def git(parser, xml_parent, data):
|
|||||||
opt, xmlopt, default_val = prop[:3]
|
opt, xmlopt, default_val = prop[:3]
|
||||||
val = entity.get(opt, default_val)
|
val = entity.get(opt, default_val)
|
||||||
if val is None:
|
if val is None:
|
||||||
raise Exception('Required option missing: %s' % opt)
|
raise JenkinsJobsException('Required option missing: %s' % opt)
|
||||||
if type(val) == bool:
|
if type(val) == bool:
|
||||||
val = str(val).lower()
|
val = str(val).lower()
|
||||||
XML.SubElement(entity_xml, xmlopt).text = val
|
XML.SubElement(entity_xml, xmlopt).text = val
|
||||||
|
@ -34,6 +34,7 @@ Example::
|
|||||||
|
|
||||||
import xml.etree.ElementTree as XML
|
import xml.etree.ElementTree as XML
|
||||||
import jenkins_jobs.modules.base
|
import jenkins_jobs.modules.base
|
||||||
|
from jenkins_jobs.errors import JenkinsJobsException
|
||||||
|
|
||||||
|
|
||||||
def email(parser, xml_parent, data):
|
def email(parser, xml_parent, data):
|
||||||
@ -79,7 +80,8 @@ class Reporters(jenkins_jobs.modules.base.Base):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if xml_parent.tag != 'maven2-moduleset':
|
if xml_parent.tag != 'maven2-moduleset':
|
||||||
raise Exception("Reporters may only be used for Maven modules.")
|
raise JenkinsJobsException("Reporters may only be used for Maven "
|
||||||
|
"modules.")
|
||||||
|
|
||||||
reporters = XML.SubElement(xml_parent, 'reporters')
|
reporters = XML.SubElement(xml_parent, 'reporters')
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ Example::
|
|||||||
|
|
||||||
import xml.etree.ElementTree as XML
|
import xml.etree.ElementTree as XML
|
||||||
import jenkins_jobs.modules.base
|
import jenkins_jobs.modules.base
|
||||||
|
from jenkins_jobs.errors import JenkinsJobsException
|
||||||
|
|
||||||
|
|
||||||
def git(self, xml_parent, data):
|
def git(self, xml_parent, data):
|
||||||
@ -209,10 +210,10 @@ def git(self, xml_parent, data):
|
|||||||
'viewgit': 'ViewGitWeb',
|
'viewgit': 'ViewGitWeb',
|
||||||
'auto': 'auto'}
|
'auto': 'auto'}
|
||||||
if browser not in browserdict:
|
if browser not in browserdict:
|
||||||
raise Exception("Browser entered is not valid must be one of: " +
|
raise JenkinsJobsException("Browser entered is not valid must be one "
|
||||||
"githubweb, fisheye, bitbucketweb, cgit, gitblit, " +
|
"of: githubweb, fisheye, bitbucketweb, "
|
||||||
"gitlab, gitoriousweb, gitweb, redmineweb, viewgit, " +
|
"cgit, gitblit, gitlab, gitoriousweb, "
|
||||||
"or auto")
|
"gitweb, redmineweb, viewgit, or auto")
|
||||||
if browser != 'auto':
|
if browser != 'auto':
|
||||||
bc = XML.SubElement(scm, 'browser', {'class':
|
bc = XML.SubElement(scm, 'browser', {'class':
|
||||||
'hudson.plugins.git.browser.' +
|
'hudson.plugins.git.browser.' +
|
||||||
@ -277,7 +278,7 @@ def repo(self, xml_parent, data):
|
|||||||
XML.SubElement(scm, 'manifestRepositoryUrl').text = \
|
XML.SubElement(scm, 'manifestRepositoryUrl').text = \
|
||||||
data['manifest-url']
|
data['manifest-url']
|
||||||
else:
|
else:
|
||||||
raise Exception("Must specify a manifest url")
|
raise JenkinsJobsException("Must specify a manifest url")
|
||||||
|
|
||||||
mapping = [
|
mapping = [
|
||||||
# option, xml name, default value
|
# option, xml name, default value
|
||||||
@ -354,7 +355,7 @@ def svn(self, xml_parent, data):
|
|||||||
XML.SubElement(module, 'remote').text = data['url']
|
XML.SubElement(module, 'remote').text = data['url']
|
||||||
XML.SubElement(module, 'local').text = data.get('basedir', '.')
|
XML.SubElement(module, 'local').text = data.get('basedir', '.')
|
||||||
else:
|
else:
|
||||||
raise Exception("A top level url or repos list must exist")
|
raise JenkinsJobsException("A top level url or repos list must exist")
|
||||||
updater = data.get('workspaceupdater', 'wipeworkspace')
|
updater = data.get('workspaceupdater', 'wipeworkspace')
|
||||||
if updater == 'wipeworkspace':
|
if updater == 'wipeworkspace':
|
||||||
updaterclass = 'CheckoutUpdater'
|
updaterclass = 'CheckoutUpdater'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user