def slave_utilization(registry, xml_parent, data): """yaml: slave-utilization This plugin allows you to specify the percentage of a slave's capacity a job wants to use. Requires the Jenkins :jenkins-wiki:`Slave Utilization Plugin <Slave+Utilization+Plugin>`. :arg int slave-percentage: Specify the percentage of a slave's execution slots that this job should occupy (default 0) :arg bool single-instance-per-slave: Control whether concurrent instances of this job will be permitted to run in parallel on a single slave (default false) Example: .. literalinclude:: /../../tests/properties/fixtures/slave-utilization1.yaml :language: yaml """ utilization = XML.SubElement( xml_parent, 'com.suryagaddipati.jenkins.SlaveUtilizationProperty') percent = int(data.get('slave-percentage', 0)) exclusive_node_access = True if percent else False mapping = [ ('', 'needsExclusiveAccessToNode', exclusive_node_access), ('', 'slaveUtilizationPercentage', percent), ('single-instance-per-slave', 'singleInstancePerSlave', False)] helpers.convert_mapping_to_xml( utilization, data, mapping, fail_required=True)
def builds_chain_fingerprinter(registry, xml_parent, data): """yaml: builds-chain-fingerprinter Builds chain fingerprinter. Requires the Jenkins :jenkins-wiki:`Builds chain fingerprinter Plugin <Builds+chain+fingerprinter>`. :arg bool per-builds-chain: enable builds hierarchy fingerprinting (default false) :arg bool per-job-chain: enable jobs hierarchy fingerprinting (default false) Example: .. literalinclude:: /../../tests/properties/fixtures/fingerprinter.yaml :language: yaml """ fingerprinter = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.' 'buildschainfingerprinter.' 'AutomaticFingerprintJobProperty') mapping = [ ('per-builds-chain', 'isPerBuildsChainEnabled', False), ('per-job-chain', 'isPerJobsChainEnabled', False), ] helpers.convert_mapping_to_xml( fingerprinter, data, mapping, fail_required=True)
def delivery_pipeline(registry, xml_parent, data): """yaml: delivery-pipeline Requires the Jenkins :jenkins-wiki:`Delivery Pipeline Plugin <Delivery+Pipeline+Plugin>`. :arg str stage: Name of the stage for this job (default '') :arg str task: Name of the task for this job (default '') :arg str description: task description template for this job (default '') Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/delivery-pipeline-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/delivery-pipeline-full.yaml :language: yaml """ pipeline = XML.SubElement( xml_parent, 'se.diabol.jenkins.pipeline.PipelineProperty') pipeline.set('plugin', 'delivery-pipeline-plugin') mapping = [ ('stage', 'stageName', ''), ('task', 'taskName', ''), ('description', 'descriptionTemplate', ''), ] helpers.convert_mapping_to_xml(pipeline, data, mapping, fail_required=True)
def rebuild(registry, xml_parent, data): """yaml: rebuild This plug-in allows the user to rebuild a parameterized build without entering the parameters again.It will also allow the user to edit the parameters before rebuilding. Requires the Jenkins :jenkins-wiki:`Rebuild Plugin <Rebuild+Plugin>`. :arg bool auto-rebuild: Rebuild without asking for parameters (default false) :arg bool rebuild-disabled: Disable rebuilding for this job (default false) Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/rebuild-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/rebuild-full.yaml :language: yaml """ sub_element = XML.SubElement(xml_parent, 'com.sonyericsson.rebuild.RebuildSettings') sub_element.set('plugin', 'rebuild') mapping = [ ('auto-rebuild', 'autoRebuild', False), ('rebuild-disabled', 'rebuildDisabled', False), ] helpers.convert_mapping_to_xml( sub_element, data, mapping, fail_required=True)
def build_discarder(registry, xml_parent, data): """yaml: build-discarder :arg int days-to-keep: Number of days to keep builds for (default -1) :arg int num-to-keep: Number of builds to keep (default -1) :arg int artifact-days-to-keep: Number of days to keep builds with artifacts (default -1) :arg int artifact-num-to-keep: Number of builds with artifacts to keep (default -1) Example: .. literalinclude:: /../../tests/properties/fixtures/build-discarder-001.yaml :language: yaml .. literalinclude:: /../../tests/properties/fixtures/build-discarder-002.yaml :language: yaml """ base_sub = XML.SubElement(xml_parent, 'jenkins.model.BuildDiscarderProperty') strategy = XML.SubElement(base_sub, 'strategy') strategy.set('class', 'hudson.tasks.LogRotator') mappings = [ ('days-to-keep', 'daysToKeep', -1), ('num-to-keep', 'numToKeep', -1), ('artifact-days-to-keep', 'artifactDaysToKeep', -1), ('artifact-num-to-keep', 'artifactNumToKeep', -1), ] helpers.convert_mapping_to_xml( strategy, data, mappings, fail_required=True)
def sidebar(registry, xml_parent, data): """yaml: sidebar Allows you to add links in the sidebar. Requires the Jenkins :jenkins-wiki:`Sidebar-Link Plugin <Sidebar-Link+Plugin>`. :arg str url: url to link to (optional) :arg str text: text for the link (optional) :arg str icon: path to icon (optional) Example: .. literalinclude:: /../../tests/properties/fixtures/sidebar02.yaml :language: yaml """ sidebar = xml_parent.find('hudson.plugins.sidebar__link.ProjectLinks') if sidebar is None: sidebar = XML.SubElement(xml_parent, 'hudson.plugins.sidebar__link.ProjectLinks') links = XML.SubElement(sidebar, 'links') else: links = sidebar.find('links') action = XML.SubElement(links, 'hudson.plugins.sidebar__link.LinkAction') mapping = [ ('url', 'url', ''), ('text', 'text', ''), ('icon', 'icon', ''), ] helpers.convert_mapping_to_xml(action, data, mapping, fail_required=True)
def slave_prerequisites(registry, xml_parent, data): """yaml: slave-prerequisites This plugin allows you to check prerequisites on slave before a job can run a build on it Requires the Jenkins :jenkins-wiki:`Slave Prerequisites Plugin <Slave+Prerequisites+Plugin>`. :arg str script: A script to be executed on slave node. If returning non 0 status, the node will be vetoed from hosting the build. (required) :arg str interpreter: Command line interpreter to be used for executing the prerequisite script - either `shell` for Unix shell or `cmd` for Windows batch script. (default shell) Example: .. literalinclude:: /../../tests/properties/fixtures/slave-prerequisites-minimal.yaml :language: yaml .. literalinclude:: /../../tests/properties/fixtures/slave-prerequisites-full.yaml :language: yaml """ prereqs = XML.SubElement(xml_parent, 'com.cloudbees.plugins.JobPrerequisites') mappings = [ ('script', 'script', None), ('interpreter', 'interpreter', 'shell', { 'cmd': 'windows batch command', 'shell': 'shell script'}), ] helpers.convert_mapping_to_xml(prereqs, data, mappings, fail_required=True)
def root_xml(self, data): root = XML.Element('hudson.model.ListView') mapping = [ ('name', 'name', None), ('description', 'description', ''), ('filter-executors', 'filterExecutors', False), ('filter-queue', 'filterQueue', False)] convert_mapping_to_xml(root, data, mapping, fail_required=True) XML.SubElement(root, 'properties', {'class': 'hudson.model.View$PropertyList'}) jn_xml = XML.SubElement(root, 'jobNames') jobnames = data.get('job-name', None) XML.SubElement(jn_xml, 'comparator', {'class': 'hudson.util.CaseInsensitiveComparator'}) if jobnames is not None: for jobname in jobnames: XML.SubElement(jn_xml, 'string').text = str(jobname) XML.SubElement(root, 'jobFilters') c_xml = XML.SubElement(root, 'columns') columns = data.get('columns', []) for column in columns: if column in COLUMN_DICT: XML.SubElement(c_xml, COLUMN_DICT[column]) mapping = [ ('regex', 'includeRegex', None), ('recurse', 'recurse', False), ('status-filter', 'statusFilter', None)] convert_mapping_to_xml(root, data, mapping, fail_required=False) return root
def random_string_param(registry, xml_parent, data): """yaml: random-string This parameter generates a random string and passes it to the build, preventing Jenkins from combining queued builds. Requires the Jenkins :jenkins-wiki:`Random String Parameter Plugin <Random+String+Parameter+Plugin>`. :arg str name: Name of the parameter :arg str description: Description of the parameter (default '') :arg str failed-validation-message: Failure message to display for invalid input (default '') Example: .. literalinclude:: /../../tests/parameters/fixtures/random-string-param001.yaml :language: yaml """ pdef = XML.SubElement(xml_parent, 'hudson.plugins.random__string__parameter.' 'RandomStringParameterDefinition') if 'name' not in data: raise JenkinsJobsException('random-string must have a name parameter.') mapping = [ ('name', 'name', None), ('description', 'description', ''), ('failed-validation-message', 'failedValidationMessage', ''), ] convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
def validating_string_param(registry, xml_parent, data): """yaml: validating-string A validating string parameter Requires the Jenkins :jenkins-wiki:`Validating String Plugin <Validating+String+Parameter+Plugin>`. :arg str name: the name of the parameter :arg str default: the default value of the parameter (optional) :arg str description: a description of the parameter (optional) :arg str regex: a regular expression to validate the string :arg str msg: a message to display upon failed validation Example:: parameters: - validating-string: name: FOO default: bar description: "A parameter named FOO, defaults to 'bar'." regex: [A-Za-z]* msg: Your entered value failed validation """ pdef = base_param(registry, xml_parent, data, True, 'hudson.plugins.validating__string__parameter.' 'ValidatingStringParameterDefinition') mapping = [ ('regex', 'regex', None), ('msg', 'failedValidationMessage', None), ] convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
def unclassified(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.UnclassifiedJobsFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def dynamic_scriptler_param_common(registry, xml_parent, data, ptype): pdef = base_param(registry, xml_parent, data, False, 'com.seitenbau.jenkins.plugins.dynamicparameter.' 'scriptler.' + ptype) parametersXML = XML.SubElement(pdef, '__parameters') parameters = data.get('parameters', []) if parameters: mapping = [ ('name', 'name', None), ('value', 'value', None), ] for parameter in parameters: parameterXML = XML.SubElement(parametersXML, 'com.seitenbau.jenkins.plugins.' 'dynamicparameter.scriptler.' 'ScriptlerParameterDefinition_' '-ScriptParameter') convert_mapping_to_xml( parameterXML, parameter, mapping, fail_required=True) mapping = [ ('script-id', '__scriptlerScriptId', None), ('remote', '__remote', False), ('read-only', 'readonlyInputField', False), ] convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
def copyartifact_build_selector_param(registry, xml_parent, data): """yaml: copyartifact-build-selector Control via a build parameter, which build the copyartifact plugin should copy when it is configured to use 'build-param'. Requires the Jenkins :jenkins-wiki:`Copy Artifact plugin <Copy+Artifact+Plugin>`. :arg str name: name of the build parameter to store the selection in :arg str description: a description of the parameter (optional) :arg str which-build: which to provide as the default value in the UI. See ``which-build`` param of :py:mod:`~builders.copyartifact` from the builders module for the available values as well as options available that control additional behaviour for the selected value. Example: .. literalinclude:: /../../tests/parameters/fixtures/copyartifact-build-selector001.yaml :language: yaml """ t = XML.SubElement(xml_parent, 'hudson.plugins.copyartifact.' 'BuildSelectorParameter') mapping = [ ('name', 'name', None), ('description', 'description', ''), ] convert_mapping_to_xml(t, data, mapping, fail_required=True) copyartifact_build_selector(t, data, 'defaultSelector')
def matrix_combinations_param(registry, xml_parent, data): """yaml: matrix-combinations Matrix combinations parameter Requires the Jenkins :jenkins-wiki:`Matrix Combinations Plugin <Matrix+Combinations+Plugin>`. :arg str name: the name of the parameter :arg str description: a description of the parameter (optional) :arg str filter: Groovy expression to use filter the combination by default (optional) Example: .. literalinclude:: \ /../../tests/parameters/fixtures/matrix-combinations-param001.yaml :language: yaml """ element_name = 'hudson.plugins.matrix__configuration__parameter.' \ 'MatrixCombinationsParameterDefinition' pdef = XML.SubElement(xml_parent, element_name) mapping = [ ('name', 'name', None), ('description', 'description', ''), ('filter', 'defaultCombinationFilter', '')] convert_mapping_to_xml(pdef, data, mapping, fail_required=True) return pdef
def svn_tags_param(registry, xml_parent, data): """yaml: svn-tags A svn tag parameter Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin <Parameterized+Trigger+Plugin>`. :arg str name: the name of the parameter :arg str default: the default value of the parameter (optional) :arg str description: a description of the parameter (optional) :arg str url: the url to list tags from :arg str filter: the regular expression to filter tags Example:: parameters: - svn-tags: name: BRANCH_NAME default: release description: A parameter named BRANCH_NAME default is release url: http://svn.example.com/repo filter: [A-za-z0-9]* """ pdef = base_param(registry, xml_parent, data, True, 'hudson.scm.listtagsparameter.' 'ListSubversionTagsParameterDefinition') mapping = [ ('url', 'tagsDir', None), ('filter', 'tagsFilter', None), ('', 'reverseByDate', "true"), ('', 'reverseByName', "false"), ('', 'maxTags', "100"), ('', 'uuid', "1-1-1-1-1"), ] convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
def branch_api(registry, xml_parent, data): """yaml: branch-api Enforces a minimum time between builds based on the desired maximum rate. Requires the Jenkins :jenkins-wiki:`Branch API Plugin <Branch+API+Plugin>`. :arg int number-of-builds: The maximum number of builds allowed within the specified time period. (default 1) :arg str time-period: The time period within which the maximum number of builds will be enforced. (default 'Hour') :valid values: **Hour**, **Day**, **Week**, **Month**, **Year** Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/branch-api-minimal.yaml :language: yaml Full example: .. literalinclude:: /../../tests/properties/fixtures/branch-api-full.yaml :language: yaml """ branch = XML.SubElement(xml_parent, 'jenkins.branch.' 'RateLimitBranchProperty_-JobPropertyImpl') branch.set('plugin', 'branch-api') valid_time_periods = ['Hour', 'Day', 'Week', 'Month', 'Year'] mapping = [ ('time-period', 'durationName', 'Hour', valid_time_periods), ('number-of-builds', 'count', 1)] helpers.convert_mapping_to_xml(branch, data, mapping, fail_required=True)
def email(registry, xml_parent, data): """yaml: email Email notifications on build failure. :arg str recipients: Recipient email addresses :arg bool notify-every-unstable-build: Send an email for every unstable build (default true) :arg bool send-to-individuals: Send an email to the individual who broke the build (default false) :arg bool notify-for-each-module: Send an email for each module (e.g. failed, unstable). (default true) Example:: reporters: - email: recipients: [email protected] """ mailer = XML.SubElement(xml_parent, 'hudson.maven.reporters.MavenMailer') XML.SubElement(mailer, 'recipients').text = data['recipients'] # Note the logic reversal (included here to match the GUI if data.get('notify-every-unstable-build', True): XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false' else: XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true' mapping = [ ('send-to-individuals', 'sendToIndividuals', False), ('notify-for-each-module', 'perModuleEmail', True), ] helpers.convert_mapping_to_xml( mailer, data, mapping, fail_required=False)
def gitbucket(parser, xml_parent, data): """yaml: gitbucket Integrate GitBucket to Jenkins. Requires the Jenkins :jenkins-wiki:`GitBucket Plugin <GitBucket+Plugin>`. :arg str url: GitBucket URL to issue (required) :arg bool link-enabled: Enable hyperlink to issue (default false) Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/gitbucket-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/gitbucket-full.yaml :language: yaml """ gitbucket = XML.SubElement( xml_parent, 'org.jenkinsci.plugins.gitbucket.GitBucketProjectProperty') gitbucket.set('plugin', 'gitbucket') mapping = [ ('url', 'url', None), ('link-enabled', 'linkEnabled', False), ] helpers.convert_mapping_to_xml( gitbucket, data, mapping, fail_required=True)
def github(registry, xml_parent, data): """yaml: github Sets the GitHub URL for the project. :arg str url: the GitHub URL (required) :arg str display-name: This value will be used as context name for commit status if status builder or status publisher is defined for this project. (>= 1.14.1) (default '') Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/github-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/github-full.yaml :language: yaml """ github = XML.SubElement( xml_parent, 'com.coravy.hudson.plugins.github.GithubProjectProperty') github.set('plugin', 'github') mapping = [ ('url', 'projectUrl', None), ('display-name', 'displayName', ''), ] helpers.convert_mapping_to_xml(github, data, mapping, fail_required=True)
def most_recent(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.MostRecentJobsFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('max-to-include', 'maxToInclude', '0'), ('check-start-time', 'checkStartTime', False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def job_type(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.JobTypeFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('job-type', 'jobType', 'hudson.model.FreeStyleProject'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def fallback(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.AddRemoveFallbackFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('fallback-type', 'fallbackTypeString', 'REMOVE_ALL_IF_ALL_INCLUDED'), ('fallback-type', 'fallbackType', 'REMOVE_ALL_IF_ALL_INCLUDED'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def scm(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.ScmTypeFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('scm-type', 'scmType', 'hudson.scm.NullSCM'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def scm(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.ScmTypeFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("scm-type", "scmType", "hudson.scm.NullSCM"), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def most_recent(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.MostRecentJobsFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('max-to-include', 'maxToInclude', '0'), ('check-start-time', 'checkStartTime', False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def job_type(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.JobTypeFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('job-type', 'jobType', 'hudson.model.FreeStyleProject'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def scm(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.ScmTypeFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('scm-type', 'scmType', 'hudson.scm.NullSCM'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def fallback(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.AddRemoveFallbackFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('fallback-type', 'fallbackTypeString', 'REMOVE_ALL_IF_ALL_INCLUDED'), ('fallback-type', 'fallbackType', 'REMOVE_ALL_IF_ALL_INCLUDED'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def label_param(registry, xml_parent, data): """yaml: label A node label parameter. :arg str name: the name of the parameter :arg str default: the default value of the parameter (optional) :arg str description: a description of the parameter (optional) :arg bool all-nodes: to run job on all nodes matching label in parallel (default: false) :arg str matching-label: to run all nodes matching label 'success', 'unstable' or 'allCases' (optional) :arg str node-eligibility: all nodes, ignore temporary nodes or ignore temporary offline nodes (optional, default all nodes) Example: .. literalinclude:: /../../tests/parameters/fixtures/node-label001.yaml :language: yaml """ pdef = base_param( registry, xml_parent, data, True, "org.jvnet.jenkins.plugins.nodelabelparameter." "LabelParameterDefinition", ) valid_types = ["allCases", "success", "unstable"] mapping = [ ("all-nodes", "allNodesMatchingLabel", False), ("matching-label", "triggerIfResult", "allCases", valid_types), ] helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True) eligibility_label = data.get("node-eligibility", "all").lower() eligibility_label_dict = { "all": "org.jvnet.jenkins.plugins." "nodelabelparameter.node." "AllNodeEligibility", "ignore-offline": "org.jvnet.jenkins.plugins." "nodelabelparameter.node." "IgnoreOfflineNodeEligibility", "ignore-temp-offline": "org.jvnet.jenkins.plugins." "nodelabelparameter.node." "IgnoreTempOfflineNodeEligibility", } if eligibility_label not in eligibility_label_dict: raise InvalidAttributeError(eligibility_label, eligibility_label, eligibility_label_dict.keys()) XML.SubElement(pdef, "nodeEligibility").set( "class", eligibility_label_dict[eligibility_label])
def regex_job(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.RegExJobFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("regex-name", "valueTypeString", ""), ("regex", "regex", ""), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def other_views(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.OtherViewsFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('view-name', 'otherViewName', '<select a view other than this one>'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def groovy_label(registry, xml_parent, data): """yaml: groovy-label This plugin allows to use Groovy script to restrict where this project can be run. Requires the Jenkins :jenkins-wiki:`Groovy Label Assignment Plugin <Groovy+Label+Assignment+plugin>`. Return value from Groovy script is treated as Label Expression. It is treated as followings: - A non-string value will be converted to a string using toString() - When null or blank string is returned, node restriction does not take effect (or is not overwritten). - When exception occurred or Label Expression is not parsed correctly, builds are canceled. :arg str script: Groovy script (default '') :arg bool sandbox: Use Groovy Sandbox. (default false) If checked, run this Groovy script in a sandbox with limited abilities. If unchecked, and you are not a Jenkins administrator, you will need to wait for an administrator to approve the script :arg list classpath: Additional classpath entries accessible from the script, each of which should be an absolute local path or URL to a JAR file, according to "The file URI Scheme" (optional) Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/groovy-label-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/groovy-label-full.yaml :language: yaml """ sub_element = XML.SubElement(xml_parent, 'jp.ikedam.jenkins.plugins.' 'groovy__label__assignment.' 'GroovyLabelAssignmentProperty') sub_element.set('plugin', 'groovy-label-assignment') security = XML.SubElement(sub_element, 'secureGroovyScript') security.set('plugin', 'script-security') mapping = [ ('script', 'script', ''), ('sandbox', 'sandbox', False), ] helpers.convert_mapping_to_xml( security, data, mapping, fail_required=True) if data and 'classpath' in data: classpath = XML.SubElement(security, 'classpath') for value in data['classpath']: entry = XML.SubElement(classpath, 'entry') XML.SubElement(entry, 'url').text = value
def regex_job(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.RegExJobFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('regex-name', 'valueTypeString', ''), ('regex', 'regex', ''), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def other_views(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.OtherViewsFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('view-name', 'otherViewName', '<select a view other than this one>'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def other_views(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.OtherViewsFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("view-name", "otherViewName", "<select a view other than this one>"), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def regex_job(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.RegExJobFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('regex-name', 'valueTypeString', ''), ('regex', 'regex', ''), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def test_convert_mapping_to_xml(self): """ Tests the test_convert_mapping_to_xml_fail_required function """ # Test default values default_root = XML.Element('testdefault') default_data = yaml.load("string: hello") default_mappings = [('default-string', 'defaultString', 'default')] convert_mapping_to_xml( default_root, default_data, default_mappings, fail_required=True) result = default_root.find('defaultString').text self.assertThat(result, Equals('default')) # Test user input user_input_root = XML.Element('testUserInput') user_input_data = yaml.load("user-input-string: hello") user_input_mappings = [('user-input-string', 'userInputString', 'user-input')] convert_mapping_to_xml( user_input_root, user_input_data, user_input_mappings, fail_required=True) result = user_input_root.find('userInputString').text self.assertThat(result, Equals('hello')) # Test missing required input required_root = XML.Element('testrequired') required_data = yaml.load("string: hello") required_mappings = [('required-string', 'requiredString', None)] self.assertRaises(MissingAttributeError, convert_mapping_to_xml, required_root, required_data, required_mappings, fail_required=True) # Test invalid user input user_input_root = XML.Element('testUserInput') user_input_data = yaml.load("user-input-string: bye") valid_inputs = ['hello'] user_input_mappings = [('user-input-string', 'userInputString', 'user-input', valid_inputs)] self.assertRaises(InvalidAttributeError, convert_mapping_to_xml, user_input_root, user_input_data, user_input_mappings)
def build_status(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.BuildStatusFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('never-built', 'neverBuilt', False), ('building', 'building', False), ('in-build-queue', 'inBuildQueue', False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_status(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.BuildStatusFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("never-built", "neverBuilt", False), ("building", "building", False), ("in-build-queue", "inBuildQueue", False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_status(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.BuildStatusFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('never-built', 'neverBuilt', False), ('building', 'building', False), ('in-build-queue', 'inBuildQueue', False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def git_scm(xml_parent, data): """Configure Git SCM Requires the :jenkins-wiki:`Git Plugin <Git+Plugin>`. :arg str url: The git repo url. (required) :arg str credentials-id: The credential to use to connect to the GIT repo. (default '') :arg bool discover-branches: Discovers branches on the repository. (default true) :arg bool discover-tags: Discovers tags on the repository. (default false) :arg bool ignore-on-push-notifications: If a job should not trigger upon push notifications. (default false) Minimal Example: .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_minimal.yaml Full Example: .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_full.yaml """ source = XML.SubElement(xml_parent, 'source', { 'class': 'jenkins.plugins.git.GitSCMSource', 'plugin': 'git', }) source_mapping = [ ('', 'id', str(uuid.uuid4())), ('url', 'remote', None), ('credentials-id', 'credentialsId', ''), ] helpers.convert_mapping_to_xml(source, data, source_mapping, fail_required=True) ########## # Traits # ########## traits_path = 'jenkins.plugins.git.traits' traits = XML.SubElement(source, 'traits') if data.get('discover-branches', True): XML.SubElement(traits, ''.join([traits_path, '.BranchDiscoveryTrait'])) if data.get('discover-tags', False): XML.SubElement(traits, ''.join([traits_path, '.TagDiscoveryTrait'])) if data.get('ignore-on-push-notifications', False): XML.SubElement( traits, ''.join([traits_path, '.IgnoreOnPushNotificationTrait']))
def build_trend(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.BuildTrendFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("build-trend-type", "buildCountTypeString", "Latest"), ("amount-type", "amountTypeString", "Hours"), ("amount", "amount", "0"), ("status", "statusTypeString", "Completed"), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def user_permissions(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.SecurityFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("configure", "configure", False), ("build", "build", False), ("workspace", "workspace", False), ("permission-check", "permissionCheckType", "MustMatchAll"), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def upstream_downstream(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.UpstreamDownstreamJobsFilter") xml.set("plugin", "view-job-filters") mapping = [ ("include-upstream", "includeUpstream", False), ("include-downstream", "includeDownstream", False), ("recursive", "recursive", False), ("exclude-originals", "excludeOriginals", False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def user_permissions(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.SecurityFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('configure', 'configure', False), ('build', 'build', False), ('workspace', 'workspace', False), ('permission-check', 'permissionCheckType', 'MustMatchAll'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_trend(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.BuildTrendFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('build-trend-type', 'buildCountTypeString', 'Latest'), ('amount-type', 'amountTypeString', 'Hours'), ('amount', 'amount', '0'), ('status', 'statusTypeString', 'Completed'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def bitbucket_scm(xml_parent, data): """Configure BitBucket scm Requires the :jenkins-wiki:`Bitbucket Branch Source Plugin <Bitbucket+Branch+Source+Plugin>`. :arg str credentials-id: The credential to use to scan BitBucket. (required) :arg str repo-owner: Specify the name of the Bitbucket Team or Bitbucket User Account. (required) :arg str repo: The BitBucket repo. (required) :arg bool discover-tags: Discovers tags on the repository. (default false) Minimal Example: .. literalinclude:: /../../tests/multibranch/fixtures/scm_bitbucket_minimal.yaml Full Example: .. literalinclude:: /../../tests/multibranch/fixtures/scm_bitbucket_full.yaml """ source = XML.SubElement( xml_parent, 'source', { 'class': 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource', 'plugin': 'cloudbees-bitbucket-branch-source', }) source_mapping = [ ('', 'id', str(uuid.uuid4())), ('repo-owner', 'repoOwner', None), ('repo', 'repository', None), ] helpers.convert_mapping_to_xml(source, data, source_mapping, fail_required=True) mapping_optional = [ ('credentials-id', 'credentialsId', None), ] helpers.convert_mapping_to_xml(source, data, mapping_optional, fail_required=False) traits = XML.SubElement(source, 'traits') if data.get('discover-tags', False): XML.SubElement( traits, 'com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait')
def upstream_downstream(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.UpstreamDownstreamJobsFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('include-upstream', 'includeUpstream', False), ('include-downstream', 'includeDownstream', False), ('recursive', 'recursive', False), ('exclude-originals', 'excludeOriginals', False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def user_permissions(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.SecurityFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('configure', 'configure', False), ('build', 'build', False), ('workspace', 'workspace', False), ('permission-check', 'permissionCheckType', 'MustMatchAll'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_trend(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.BuildTrendFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('build-trend-type', 'buildCountTypeString', 'Latest'), ('amount-type', 'amountTypeString', 'Hours'), ('amount', 'amount', '0'), ('status', 'statusTypeString', 'Completed'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_duration(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.BuildDurationFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("build-duration-type", "buildCountTypeString", "Latest"), ("amount-type", "amountTypeString", "Hours"), ("amount", "amount", "0"), ("less-than", "lessThan", True), ("build-duration-minutes", "buildDurationMinutes", "0"), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def job_status(xml_parent, data): xml = XML.SubElement(xml_parent, "hudson.views.JobStatusFilter") xml.set("plugin", "view-job-filters") mapping = [ ("match-type", "includeExcludeTypeString", "includeMatched"), ("unstable", "unstable", False), ("failed", "failed", False), ("aborted", "aborted", False), ("disabled", "disabled", False), ("stable", "stable", False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_duration(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.BuildDurationFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('build-duration-type', 'buildCountTypeString', 'Latest'), ('amount-type', 'amountTypeString', 'Hours'), ('amount', 'amount', '0'), ('less-than', 'lessThan', True), ('build-duration-minutes', 'buildDurationMinutes', '0'), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def job_status(xml_parent, data): xml = XML.SubElement(xml_parent, 'hudson.views.JobStatusFilter') xml.set('plugin', 'view-job-filters') mapping = [ ('match-type', 'includeExcludeTypeString', 'includeMatched'), ('unstable', 'unstable', False), ('failed', 'failed', False), ('aborted', 'aborted', False), ('disabled', 'disabled', False), ('stable', 'stable', False), ] helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def label_param(registry, xml_parent, data): """yaml: label A node label parameter. :arg str name: the name of the parameter :arg str default: the default value of the parameter (optional) :arg str description: a description of the parameter (optional) :arg str matching-label: to run all nodes matching label 'success', 'unstable' or 'allCases' (optional) :arg str node-eligibility: all nodes, ignore temporary nodes or ignore temporary offline nodes (optional, default all nodes) Example: .. literalinclude:: /../../tests/parameters/fixtures/node-label001.yaml :language: yaml """ pdef = base_param( registry, xml_parent, data, True, 'org.jvnet.jenkins.plugins.nodelabelparameter.' 'LabelParameterDefinition') XML.SubElement(pdef, 'allNodesMatchingLabel').text = "true" valid_types = ['allCases', 'success', 'unstable'] mapping = [ ('matching-label', 'triggerIfResult', 'allCases', valid_types), ] helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True) eligibility_label = data.get('node-eligibility', 'all').lower() eligibility_label_dict = { 'all': 'org.jvnet.jenkins.plugins.' 'nodelabelparameter.node.' 'AllNodeEligibility', 'ignore-offline': 'org.jvnet.jenkins.plugins.' 'nodelabelparameter.node.' 'IgnoreOfflineNodeEligibility', 'ignore-temp-offline': 'org.jvnet.jenkins.plugins.' 'nodelabelparameter.node.' 'IgnoreTempOfflineNodeEligibility', } if eligibility_label not in eligibility_label_dict: raise InvalidAttributeError(eligibility_label, eligibility_label, eligibility_label_dict.keys()) XML.SubElement(pdef, 'nodeEligibility').set( "class", eligibility_label_dict[eligibility_label])
def docker_container(registry, xml_parent, data): """yaml: docker-container Requires the Jenkins: :jenkins-plugins:`Docker Plugin <docker-plugin>`. :arg str docker-registry-url: URL of the Docker registry. (default '') :arg str credentials-id: Credentials Id for the Docker registey. (default '') :arg bool commit-on-success: When a job completes, the docker slave instance is committed with repository based on the job name and build number as tag. (default false) :arg str additional-tag: Additional tag to apply to the docker slave instance when committing it. (default '') :arg bool push-on-success: Also push the resulting image when committing the docker slave instance. (default false) :arg bool clean-local-images: Clean images from the local daemon after building. (default true) Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/docker-container-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/docker-container-full.yaml :language: yaml """ xml_docker = XML.SubElement( xml_parent, "com.nirima.jenkins.plugins.docker.DockerJobProperty") registry = XML.SubElement(xml_docker, "registry") registry.set("plugin", "docker-commons") registry_mapping = [ ("docker-registry-url", "url", ""), ("credentials-id", "credentialsId", ""), ] helpers.convert_mapping_to_xml(registry, data, registry_mapping, fail_required=False) mapping = [ ("commit-on-success", "tagOnCompletion", False), ("additional-tag", "additionalTag", ""), ("push-on-success", "pushOnSuccess", False), ("clean-local-images", "cleanImages", True), ] helpers.convert_mapping_to_xml(xml_docker, data, mapping, fail_required=True)
def build_blocker(registry, xml_parent, data): """yaml: build-blocker This plugin keeps the actual job in the queue if at least one name of currently running jobs is matching with one of the given regular expressions. Requires the Jenkins :jenkins-wiki:`Build Blocker Plugin <Build+Blocker+Plugin>`. :arg bool use-build-blocker: Enable or disable build blocker (default true) :arg list blocking-jobs: One regular expression per line to select blocking jobs by their names (required) :arg str block-level: block build globally ('GLOBAL') or per node ('NODE') (default 'GLOBAL') :arg str queue-scanning: scan build queue for all builds ('ALL') or only buildable builds ('BUILDABLE') (default 'DISABLED') Example: Minimal Example: .. literalinclude:: /../../tests/properties/fixtures/build-blocker-minimal.yaml :language: yaml Full Example: .. literalinclude:: /../../tests/properties/fixtures/build-blocker-full.yaml :language: yaml """ blocker = XML.SubElement(xml_parent, 'hudson.plugins.' 'buildblocker.BuildBlockerProperty') if data is None or 'blocking-jobs' not in data: raise JenkinsJobsException('blocking-jobs field is missing') elif data.get('blocking-jobs', None) is None: raise JenkinsJobsException('blocking-jobs list must not be empty') jobs = '' for setting, value in data.items(): if setting == 'blocking-jobs': jobs = '\n'.join(value) block_level_types = ['GLOBAL', 'NODE'] queue_scan_types = ['DISABLED', 'ALL', 'BUILDABLE'] mapping = [ ('use-build-blocker', 'useBuildBlocker', True), ('', 'blockingJobs', jobs), ('block-level', 'blockLevel', 'GLOBAL', block_level_types), ('queue-scanning', 'scanQueueFor', 'DISABLED', queue_scan_types), ] helpers.convert_mapping_to_xml(blocker, data, mapping, fail_required=True)
def test_convert_mapping_to_xml(self): """ Tests the test_convert_mapping_to_xml_fail_required function """ # Test default values default_root = XML.Element('testdefault') default_data = yaml.load("string: hello") default_mappings = [('default-string', 'defaultString', 'default')] convert_mapping_to_xml(default_root, default_data, default_mappings, fail_required=True) result = default_root.find('defaultString').text self.assertThat(result, Equals('default')) # Test user input user_input_root = XML.Element('testUserInput') user_input_data = yaml.load("user-input-string: hello") user_input_mappings = [('user-input-string', 'userInputString', 'user-input')] convert_mapping_to_xml(user_input_root, user_input_data, user_input_mappings, fail_required=True) result = user_input_root.find('userInputString').text self.assertThat(result, Equals('hello')) # Test missing required input required_root = XML.Element('testrequired') required_data = yaml.load("string: hello") required_mappings = [('required-string', 'requiredString', None)] self.assertRaises(MissingAttributeError, convert_mapping_to_xml, required_root, required_data, required_mappings, fail_required=True) # Test invalid user input user_input_root = XML.Element('testUserInput') user_input_data = yaml.load("user-input-string: bye") valid_inputs = ['hello'] user_input_mappings = [('user-input-string', 'userInputString', 'user-input', valid_inputs)] self.assertRaises(InvalidAttributeError, convert_mapping_to_xml, user_input_root, user_input_data, user_input_mappings)
def root_xml(self, data): xml_parent = XML.Element("com.cloudbees.plugins.flow.BuildFlow") needs_workspace = data.get("needs-workspace", False) mapping = [ ("dsl", "dsl", ""), ("needs-workspace", "buildNeedsWorkspace", False), ] convert_mapping_to_xml(xml_parent, data, mapping, fail_required=True) if needs_workspace and "dsl-file" in data: XML.SubElement(xml_parent, "dslFile").text = data["dsl-file"] return xml_parent