diff options
author | Zuul <zuul@review.opendev.org> | 2020-05-25 19:36:55 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-05-25 19:36:55 +0000 |
commit | 2b238d656df69641b377c243d991c7f20d4e1c6d (patch) | |
tree | ca8859d358764a83afae9f0f55328c8972ec72af | |
parent | 2eb74a15cd8e237902578321b2f131cffe7757fc (diff) | |
parent | 8625fe2a975524f0f3382959ec8f4132b353c278 (diff) | |
download | python-jenkins-job-builder-2b238d656df69641b377c243d991c7f20d4e1c6d.tar.gz python-jenkins-job-builder-2b238d656df69641b377c243d991c7f20d4e1c6d.tar.xz python-jenkins-job-builder-2b238d656df69641b377c243d991c7f20d4e1c6d.zip |
Merge "Pipelines: stop producing unsupported and deprecated XML tags"
-rw-r--r-- | jenkins_jobs/modules/general.py | 49 | ||||
-rwxr-xr-x | jenkins_jobs/modules/publishers.py | 6 | ||||
-rw-r--r-- | jenkins_jobs/modules/scm.py | 10 | ||||
-rw-r--r-- | jenkins_jobs/modules/triggers.py | 13 | ||||
-rw-r--r-- | jenkins_jobs/modules/wrappers.py | 4 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_concurrent.xml | 12 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_concurrent.yaml | 6 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template001.xml | 11 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template002.xml | 11 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template003.xml | 11 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template004.xml | 11 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template005.xml | 38 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template005.yaml | 12 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_template006.xml | 11 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_triggers.xml | 21 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/project_pipeline_triggers.yaml | 7 |
16 files changed, 134 insertions, 99 deletions
diff --git a/jenkins_jobs/modules/general.py b/jenkins_jobs/modules/general.py index 0e2bea24..daa6d1d7 100644 --- a/jenkins_jobs/modules/general.py +++ b/jenkins_jobs/modules/general.py @@ -144,23 +144,35 @@ class General(jenkins_jobs.modules.base.Base): if "display-name" in data: XML.SubElement(xml, "displayName").text = data["display-name"] - if data.get("block-downstream"): - XML.SubElement(xml, "blockBuildWhenDownstreamBuilding").text = "true" - else: - XML.SubElement(xml, "blockBuildWhenDownstreamBuilding").text = "false" - if data.get("block-upstream"): - XML.SubElement(xml, "blockBuildWhenUpstreamBuilding").text = "true" - else: - XML.SubElement(xml, "blockBuildWhenUpstreamBuilding").text = "false" + if data.get("project-type", "freestyle") != "pipeline": + if data.get("block-downstream"): + XML.SubElement(xml, "blockBuildWhenDownstreamBuilding").text = "true" + else: + XML.SubElement(xml, "blockBuildWhenDownstreamBuilding").text = "false" + if data.get("block-upstream"): + XML.SubElement(xml, "blockBuildWhenUpstreamBuilding").text = "true" + else: + XML.SubElement(xml, "blockBuildWhenUpstreamBuilding").text = "false" authtoken = data.get("auth-token", None) if authtoken is not None: XML.SubElement(xml, "authToken").text = authtoken - if data.get("concurrent"): - XML.SubElement(xml, "concurrentBuild").text = "true" + if data.get("project-type", "freestyle") != "pipeline": + if data.get("concurrent"): + XML.SubElement(xml, "concurrentBuild").text = "true" + else: + XML.SubElement(xml, "concurrentBuild").text = "false" else: - XML.SubElement(xml, "concurrentBuild").text = "false" - if "workspace" in data: - XML.SubElement(xml, "customWorkspace").text = str(data["workspace"]) + if not data.get("concurrent"): + properties = xml.find("properties") + if properties is None: + properties = XML.SubElement(xml, "properties") + XML.SubElement( + properties, + "org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty", + ) + if data.get("project-type", "freestyle") != "pipeline": + if "workspace" in data: + XML.SubElement(xml, "customWorkspace").text = str(data["workspace"]) if (xml.tag == "matrix-project") and ("child-workspace" in data): XML.SubElement(xml, "childCustomWorkspace").text = str( data["child-workspace"] @@ -168,11 +180,12 @@ class General(jenkins_jobs.modules.base.Base): if "quiet-period" in data: XML.SubElement(xml, "quietPeriod").text = str(data["quiet-period"]) node = data.get("node", None) - if node: - XML.SubElement(xml, "assignedNode").text = node - XML.SubElement(xml, "canRoam").text = "false" - else: - XML.SubElement(xml, "canRoam").text = "true" + if data.get("project-type", "freestyle") != "pipeline": + if node: + XML.SubElement(xml, "assignedNode").text = node + XML.SubElement(xml, "canRoam").text = "false" + else: + XML.SubElement(xml, "canRoam").text = "true" if "retry-count" in data: XML.SubElement(xml, "scmCheckoutRetryCount").text = str(data["retry-count"]) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 4702c811..68b93e73 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -39,6 +39,8 @@ import jenkins_jobs.modules.base from jenkins_jobs.modules import hudson_model import jenkins_jobs.modules.helpers as helpers +logger = logging.getLogger(__name__) + def influx_db(registry, xml_parent, data): """yaml: influx-db @@ -8187,6 +8189,10 @@ class Publishers(jenkins_jobs.modules.base.Base): component_list_type = "publishers" def gen_xml(self, xml_parent, data): + if data.get("project-type", "freestyle") == "pipeline": + logger.debug("Publishers skipped for Pipeline job") + return + publishers = XML.SubElement(xml_parent, "publishers") for action in data.get("publishers", []): diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index c594ff20..193ceccd 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -1679,8 +1679,14 @@ class SCM(jenkins_jobs.modules.base.Base): def gen_xml(self, xml_parent, data): # multibranch-pipeline scm implementation is incompatible with SCM - if data.get("project-type") in ["multibranch", "multibranch-defaults"]: - logging.debug("SCM Module skipped for multibranch project-type.") + if data.get("project-type") in [ + "multibranch", + "multibranch-defaults", + "pipeline", + ]: + logging.debug( + "SCM Module skipped for %s project-type." % data.get("project-type") + ) return scms_parent = XML.Element("scms") diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 43128489..2f89b5c6 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -2454,6 +2454,17 @@ class Triggers(jenkins_jobs.modules.base.Base): if not triggers: return - trig_e = XML.SubElement(xml_parent, "triggers", {"class": "vector"}) + if data.get("project-type", "freestyle") != "pipeline": + trig_e = XML.SubElement(xml_parent, "triggers", {"class": "vector"}) + else: + properties = xml_parent.find("properties") + if properties is None: + properties = XML.SubElement(xml_parent, "properties") + pipeline_trig_prop = XML.SubElement( + properties, + "org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty", + ) + trig_e = XML.SubElement(pipeline_trig_prop, "triggers") + for trigger in triggers: self.registry.dispatch("trigger", trig_e, trigger) diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 77230c8e..9a2a01c8 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -2962,6 +2962,10 @@ class Wrappers(jenkins_jobs.modules.base.Base): component_list_type = "wrappers" def gen_xml(self, xml_parent, data): + if data.get("project-type", "freestyle") == "pipeline": + logger.debug("Build wrappers skipped for Pipeline job") + return + wrappers = XML.SubElement(xml_parent, "buildWrappers") for wrap in data.get("wrappers", []): diff --git a/tests/yamlparser/fixtures/project_pipeline_concurrent.xml b/tests/yamlparser/fixtures/project_pipeline_concurrent.xml new file mode 100644 index 00000000..d94b5b7f --- /dev/null +++ b/tests/yamlparser/fixtures/project_pipeline_concurrent.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<flow-definition plugin="workflow-job"> + <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps"> + <script>build job: "job1" +</script> + <sandbox>false</sandbox> + </definition> + <actions/> + <description><!-- Managed by Jenkins Job Builder --></description> + <keepDependencies>false</keepDependencies> + <properties/> +</flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_concurrent.yaml b/tests/yamlparser/fixtures/project_pipeline_concurrent.yaml new file mode 100644 index 00000000..410ca4e4 --- /dev/null +++ b/tests/yamlparser/fixtures/project_pipeline_concurrent.yaml @@ -0,0 +1,6 @@ +- job: + name: test_job + project-type: pipeline + dsl: | + build job: "job1" + concurrent: true diff --git a/tests/yamlparser/fixtures/project_pipeline_template001.xml b/tests/yamlparser/fixtures/project_pipeline_template001.xml index f82dbe50..1921a332 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template001.xml +++ b/tests/yamlparser/fixtures/project_pipeline_template001.xml @@ -14,12 +14,7 @@ parallel [ <actions/> <description><!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers/> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_template002.xml b/tests/yamlparser/fixtures/project_pipeline_template002.xml index f92286df..82b941f0 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template002.xml +++ b/tests/yamlparser/fixtures/project_pipeline_template002.xml @@ -14,12 +14,7 @@ parallel [ <actions/> <description><!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers/> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_template003.xml b/tests/yamlparser/fixtures/project_pipeline_template003.xml index 8274d6a0..4992c5f9 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template003.xml +++ b/tests/yamlparser/fixtures/project_pipeline_template003.xml @@ -14,12 +14,7 @@ parallel [ <actions/> <description><!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers/> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_template004.xml b/tests/yamlparser/fixtures/project_pipeline_template004.xml index cd79ab94..f5a099be 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template004.xml +++ b/tests/yamlparser/fixtures/project_pipeline_template004.xml @@ -16,12 +16,7 @@ <actions/> <description><!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers/> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_template005.xml b/tests/yamlparser/fixtures/project_pipeline_template005.xml index 7bafcbfe..65940209 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template005.xml +++ b/tests/yamlparser/fixtures/project_pipeline_template005.xml @@ -13,22 +13,11 @@ <scriptPath>Jenkinsfile</scriptPath> </definition> <actions/> - <description><!-- Managed by Jenkins Job Builder --></description> + <description>maintainer: qa@example.org<!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers> - <hudson.tasks.Mailer plugin="mailer"> - <recipients>qa@example.org</recipients> - <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild> - <sendToIndividuals>false</sendToIndividuals> - </hudson.tasks.Mailer> - </publishers> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> <BLANKLINE> <?xml version="1.0" encoding="utf-8"?> @@ -46,20 +35,9 @@ <scriptPath>Jenkinsfile</scriptPath> </definition> <actions/> - <description><!-- Managed by Jenkins Job Builder --></description> + <description>maintainer: dev@example.org<!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers> - <hudson.tasks.Mailer plugin="mailer"> - <recipients>dev@example.org</recipients> - <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild> - <sendToIndividuals>false</sendToIndividuals> - </hudson.tasks.Mailer> - </publishers> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_template005.yaml b/tests/yamlparser/fixtures/project_pipeline_template005.yaml index 851feaf9..3865f019 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template005.yaml +++ b/tests/yamlparser/fixtures/project_pipeline_template005.yaml @@ -12,9 +12,7 @@ scm: - project-scm sandbox: true - publishers: - - email: - recipients: '{mail-to}' + description: 'maintainer: {maintainer}' - job-template: name: '{name}-perf-tests' @@ -23,17 +21,15 @@ scm: - project-scm sandbox: false - publishers: - - email: - recipients: '{mail-to}' + description: 'maintainer: {maintainer}' - job-group: name: '{name}-tests' jobs: - '{name}-unit-tests': - mail-to: dev@example.org + maintainer: dev@example.org - '{name}-perf-tests': - mail-to: qa@example.org + maintainer: qa@example.org - project: name: project-name diff --git a/tests/yamlparser/fixtures/project_pipeline_template006.xml b/tests/yamlparser/fixtures/project_pipeline_template006.xml index 6fdc6522..3db385db 100644 --- a/tests/yamlparser/fixtures/project_pipeline_template006.xml +++ b/tests/yamlparser/fixtures/project_pipeline_template006.xml @@ -10,12 +10,7 @@ <actions/> <description><!-- Managed by Jenkins Job Builder --></description> <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties/> - <scm class="hudson.scm.NullSCM"/> - <publishers/> - <buildWrappers/> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + </properties> </flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_triggers.xml b/tests/yamlparser/fixtures/project_pipeline_triggers.xml new file mode 100644 index 00000000..ed964de8 --- /dev/null +++ b/tests/yamlparser/fixtures/project_pipeline_triggers.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<flow-definition plugin="workflow-job"> + <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps"> + <script>build job: "job1" +</script> + <sandbox>false</sandbox> + </definition> + <actions/> + <description><!-- Managed by Jenkins Job Builder --></description> + <keepDependencies>false</keepDependencies> + <properties> + <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/> + <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> + <triggers> + <hudson.triggers.TimerTrigger> + <spec>@daily</spec> + </hudson.triggers.TimerTrigger> + </triggers> + </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> + </properties> +</flow-definition> diff --git a/tests/yamlparser/fixtures/project_pipeline_triggers.yaml b/tests/yamlparser/fixtures/project_pipeline_triggers.yaml new file mode 100644 index 00000000..6021ae01 --- /dev/null +++ b/tests/yamlparser/fixtures/project_pipeline_triggers.yaml @@ -0,0 +1,7 @@ +- job: + name: test_job + project-type: pipeline + dsl: | + build job: "job1" + triggers: + - timed: '@daily' |