Skip to content

Commit

Permalink
Merge e2560c1 into 4c8d047
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFriendlyCoder committed May 12, 2019
2 parents 4c8d047 + e2560c1 commit 8a53eec
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/pyjen/plugins/multibranch_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Primitives that manage Jenkins job of type 'multibranch pipeline'"""
from pyjen.job import Job


class MultibranchPipelineJob(Job):
"""Jenkins job of type 'multibranch pipeline'"""

@property
def jobs(self):
"""Gets all branch jobs managed by this multibranch pipeline
:rtype: :class:`list` of :class:`pyjen.plugins.pipelinejob.PipelineJob`
"""
data = self._api.get_api_data(query_params="depth=2")

retval = list()
for j in data["jobs"]:
retval.append(Job.instantiate(j, self._api))

return retval

# --------------------------------------------------------------- PLUGIN API
@staticmethod
def get_jenkins_plugin_name():
"""Gets the name of the Jenkins plugin associated with this PyJen plugin
This static method is used by the PyJen plugin API to associate this
class with a specific Jenkins plugin, as it is encoded in the config.xml
:rtype: :class:`str`
"""
return "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject"

@staticmethod
def template_config_xml():
return """<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch@2.21">
<actions/>
<description/>
<properties>
<org.jenkinsci.plugins.pipeline.modeldefinition.config.FolderConfig plugin="pipeline-model-definition@1.3.8">
<dockerLabel/>
<registry plugin="docker-commons@1.14"/>
</org.jenkinsci.plugins.pipeline.modeldefinition.config.FolderConfig>
</properties>
<folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api@2.4.0">
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
</folderViews>
<healthMetrics>
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder@6.8">
<nonRecursive>false</nonRecursive>
</com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
</healthMetrics>
<icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api@2.4.0">
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
</icon>
<orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder@6.8">
<pruneDeadBranches>true</pruneDeadBranches>
<daysToKeep>-1</daysToKeep>
<numToKeep>-1</numToKeep>
</orphanedItemStrategy>
<triggers/>
<disabled>false</disabled>
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api@2.4.0">
<data/>
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
</sources>
<factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
<scriptPath>Jenkinsfile</scriptPath>
</factory>
</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>"""


PluginClass = MultibranchPipelineJob

if __name__ == "__main__": # pragma: no cover
pass

51 changes: 51 additions & 0 deletions src/pyjen/plugins/multijob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Primitives that manage Jenkins job of type 'MultiJob'"""
from pyjen.job import Job


class MultiJob(Job):
"""Custom job type provided by the jenkins-multijob-plugin plugin
https://plugins.jenkins.io/jenkins-multijob-plugin
"""
@staticmethod
def get_jenkins_plugin_name():
"""Gets the name of the Jenkins plugin associated with this PyJen plugin
This static method is used by the PyJen plugin API to associate this
class with a specific Jenkins plugin, as it is encoded in the config.xml
:rtype: :class:`str`
"""
return "com.tikal.jenkins.plugins.multijob.MultiJobProject"

@staticmethod
def template_config_xml():
return """<com.tikal.jenkins.plugins.multijob.MultiJobProject plugin="jenkins-multijob-plugin@1.32">
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin@1.7.3">
<useBuildBlocker>false</useBuildBlocker>
<blockLevel>GLOBAL</blockLevel>
<scanQueueFor>DISABLED</scanQueueFor>
<blockingJobs/>
</hudson.plugins.buildblocker.BuildBlockerProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
<buildWrappers/>
<pollSubjobs>false</pollSubjobs>
</com.tikal.jenkins.plugins.multijob.MultiJobProject>"""


PluginClass = MultiJob

if __name__ == "__main__": # pragma: no cover
pass
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"conditional-buildstep",
"parameterized-trigger",
"build-blocker-plugin",
"jenkins-multijob-plugin",
]


Expand Down
29 changes: 29 additions & 0 deletions tests/test_jobs/test_multibranch_pipeline_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from ..utils import clean_job
from pyjen.jenkins import Jenkins
from pyjen.plugins.multibranch_pipeline import MultibranchPipelineJob


def test_create_multibranch_pipeline_job(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
expected_name = "test_create_multibranch_pipeline_job"
jb = jk.create_job(expected_name, MultibranchPipelineJob)
with clean_job(jb):
assert jb is not None
assert jb.name == expected_name


def test_get_branch_jobs(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
expected_name = "test_get_branch_jobs"
jb = jk.create_job(expected_name, MultibranchPipelineJob)
with clean_job(jb):
res = jb.jobs

assert res is not None
assert isinstance(res, list)
assert len(res) == 0


if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])
17 changes: 17 additions & 0 deletions tests/test_jobs/test_multijob_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
from ..utils import clean_job
from pyjen.jenkins import Jenkins
from pyjen.plugins.multijob import MultiJob


def test_create_multijob_job(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
expected_name = "test_create_multijob_job"
jb = jk.create_job(expected_name, MultiJob)
with clean_job(jb):
assert jb is not None
assert jb.name == expected_name


if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])

0 comments on commit 8a53eec

Please sign in to comment.