Pipelines: stop producing unsupported and deprecated XML tags

The changes include:
- <concurrentBuild> should now be represented as
  <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
  property
- <triggers> should now be localed inside
  <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
  property, in <properties> section
- unsupported XML elements got removed:
  - <blockBuildWhenDownstreamBuilding>
  - <blockBuildWhenUpstreamBuilding>
  - <assignedNode>
  - <canRoam>
  - <customWorkspace>
- got rid of publishers from project_pipeline_template005.{xml,yaml} as
  these are not supported in Pipeline jobs

The above changes align the produced XMLs with the ones from Jenkins 2.190.1
and Pipeline plugin v2.6.

Task: 39836
Story: 2007708

Change-Id: I650ef2ee60e872cce8f93de5f391933d68ec81f0
This commit is contained in:
Adam Romanek 2020-05-25 13:58:04 +02:00
parent 074985c7ff
commit 8625fe2a97
16 changed files with 134 additions and 99 deletions

View File

@ -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"])

View File

@ -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", []):

View File

@ -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")

View File

@ -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)

View File

@ -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", []):

View File

@ -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: &quot;job1&quot;
</script>
<sandbox>false</sandbox>
</definition>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<properties/>
</flow-definition>

View File

@ -0,0 +1,6 @@
- job:
name: test_job
project-type: pipeline
dsl: |
build job: "job1"
concurrent: true

View File

@ -14,12 +14,7 @@ parallel [
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -14,12 +14,7 @@ parallel [
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -14,12 +14,7 @@ parallel [
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -16,12 +16,7 @@
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -13,22 +13,11 @@
<scriptPath>Jenkinsfile</scriptPath>
</definition>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<description>maintainer: qa@example.org&lt;!-- Managed by Jenkins Job Builder --&gt;</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>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<description>maintainer: dev@example.org&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -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

View File

@ -10,12 +10,7 @@
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -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: &quot;job1&quot;
</script>
<sandbox>false</sandbox>
</definition>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View File

@ -0,0 +1,7 @@
- job:
name: test_job
project-type: pipeline
dsl: |
build job: "job1"
triggers:
- timed: '@daily'