本文整理汇总了Python中pyjen.jenkins.Jenkins类的典型用法代码示例。如果您正苦于以下问题:Python Jenkins类的具体用法?Python Jenkins怎么用?Python Jenkins使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Jenkins类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_missing_view
def test_find_missing_view(self):
# test logic
j = Jenkins(self.mock_jenkins_data_io)
View = j.find_view("DoesNotExist")
# verification
self.assertEqual(View, None, "No valid view should have been found.")
示例2: test_param_trigger
def test_param_trigger(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
upstream_name = "test_param_trigger"
jb = jk.create_job(upstream_name, FreestyleJob)
with clean_job(jb):
downstream_name = "sample_job"
new_trigger = BuildTriggerConfig.instantiate([downstream_name])
pub = ParameterizedBuildTrigger.instantiate([new_trigger])
jb.add_publisher(pub)
# Get a fresh copy of our job to ensure we have an up to date
# copy of the config.xml for the job
async_assert(lambda: jk.find_job(upstream_name).publishers)
pubs = jk.find_job(upstream_name).publishers
assert isinstance(pubs, list)
assert len(pubs) == 1
assert isinstance(pubs[0], ParameterizedBuildTrigger)
triggers = pubs[0].triggers
assert isinstance(triggers, list)
assert len(triggers) == 1
names = triggers[0].job_names
assert isinstance(names, list)
assert len(names) == 1
assert names[0] == downstream_name
assert triggers[0].condition == "SUCCESS"
示例3: test_find_job_no_jobs
def test_find_job_no_jobs(self):
mock_data_io = MagicMock()
mock_data_io.get_api_data.return_value = {'jobs':{}}
j = Jenkins(mock_data_io)
njob = j.find_job("MyJob")
self.assertEqual(njob, None, "No jobs should be found by the search method")
示例4: test_wait_for_idle
def test_wait_for_idle(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
node = jk.nodes[0]
expected_job_name = "test_wait_for_idle_job"
jb = jk.create_job(expected_job_name, FreestyleJob)
with clean_job(jb):
jb.quiet_period = 0
shell_builder = ShellBuilder.instantiate("sleep 2")
jb.add_builder(shell_builder)
# Get a fresh copy of our job to ensure we have an up to date
# copy of the config.xml for the job
async_assert(lambda: jk.find_job(expected_job_name).builders)
# Trigger a build
jb.start_build()
# The 'last_build' reference becomes available as soon as the previously
# triggered build exits the queue and starts running. So we wait for the
# last build to become valid before checking the node activity
async_assert(lambda: jb.last_build)
assert node.is_idle is False
assert node.wait_for_idle()
assert node.is_idle
示例5: test_trigger_with_current_build_params
def test_trigger_with_current_build_params(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
upstream_name = "test_trigger_with_current_build_params"
jb = jk.create_job(upstream_name, FreestyleJob)
with clean_job(jb):
downstream_name = "sample_job"
new_trigger = BuildTriggerConfig.instantiate([downstream_name])
cur_bld_params = CurrentBuildParams.instantiate()
new_trigger.add_build_param(cur_bld_params)
new_pub = ParameterizedBuildTrigger.instantiate([new_trigger])
jb.add_publisher(new_pub)
# Get a fresh copy of our job to ensure we have an up to date
# copy of the config.xml for the job
async_assert(lambda: jk.find_job(upstream_name).publishers)
pubs = jk.find_job(upstream_name).publishers
assert len(pubs) == 1
cur_pub = pubs[0]
assert len(cur_pub.triggers) == 1
cur_trig = cur_pub.triggers[0]
assert len(cur_trig.build_params) == 1
cur_param_cfg = cur_trig.build_params[0]
assert isinstance(cur_param_cfg, CurrentBuildParams)
示例6: test_create_multijob_job
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
示例7: test_find_node
def test_find_node(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
expected_name = "master"
result = jk.find_node(expected_name)
assert result is not None
assert result.name == expected_name
示例8: test_find_multiple_nested_sub_views
def test_find_multiple_nested_sub_views(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
parent1 = jk.create_view("test_find_multiple_nested_sub_views_parent1", NestedView)
with clean_view(parent1):
parent2 = parent1.create_view("test_find_multiple_nested_sub_views_parent2", NestedView)
with clean_view(parent2):
expected_view_name = "test_find_multiple_nested_sub_views_child"
# Views in Jenkins must be unique within the same parent view, but
# nested views may contain sub-views with the same name as their
# ancestors / siblings. So we create 2 views with the same name in
# each of our parent views to make sure they get resolved correctly
child1 = parent1.create_view(expected_view_name, ListView)
assert child1 is not None
with clean_view(child1):
child2 = parent2.create_view(expected_view_name, ListView)
assert child2 is not None
with clean_view(child2):
results = parent1.find_all_views(expected_view_name)
assert results is not None
assert isinstance(results, list)
assert len(results) == 2
assert results[0].name == expected_view_name
assert results[1].name == expected_view_name
示例9: test_get_user_id
def test_get_user_id(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
user = jk.find_user("admin")
result = user.user_id
assert result is not None
assert result == "admin"
示例10: test_rename_view
def test_rename_view(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
original_view_name = "test_rename_view"
v = jk.create_view(original_view_name, SectionedView)
try:
expected_section_name = "MyNewSection"
v.add_section("hudson.plugins.sectioned_view.TextSection", expected_section_name)
expected_view_name = "test_rename_view2"
v.rename(expected_view_name)
assert jk.find_view(original_view_name) is None
finally:
tmp = jk.find_view(original_view_name)
if tmp:
tmp.delete()
with clean_view(v):
assert v.name == expected_view_name
tmp_view = jk.find_view(expected_view_name)
assert tmp_view is not None
assert tmp_view.name == expected_view_name
result = tmp_view.sections
assert result is not None
assert isinstance(result, list)
assert len(result) == 1
assert result[0].name == expected_section_name
示例11: test_find_view
def test_find_view(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
expected_name = "all"
v = jk.find_view(expected_name)
assert v is not None
assert v.name == expected_name
示例12: test_build_blocker_functionality
def test_build_blocker_functionality(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
job_name1 = "test_build_blocker_functionality1"
jb1 = jk.create_job(job_name1, FreestyleJob)
with clean_job(jb1):
job_name2 = "test_build_blocker_functionality2"
jb2 = jk.create_job(job_name2, FreestyleJob)
with clean_job(jb2):
expected_jobs = job_name2
build_blocker = BuildBlockerProperty.instantiate(expected_jobs)
jb1.quiet_period = 0
jb1.add_property(build_blocker)
# Get a fresh copy of our job to ensure we have an up to date
# copy of the config.xml for the job
async_assert(lambda: jk.find_job(job_name1).properties)
build_step = ShellBuilder.instantiate("sleep 10")
jb2.quiet_period = 0
jb2.add_builder(build_step)
async_assert(lambda: jb2.builders)
queue2 = jb2.start_build()
async_assert(lambda: not queue2.waiting)
queue1 = jb1.start_build()
assert job_name2 in queue1.reason
queue2.build.abort()
assert queue1.waiting is False
示例13: test_never_run_condition
def test_never_run_condition(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
expected_job_name = "test_never_run_condition"
jb = jk.create_job(expected_job_name, FreestyleJob)
with clean_job(jb):
expected_output = "Here is my sample output..."
shell_builder = ShellBuilder.instantiate("echo " + expected_output)
condition = NeverRun.instantiate()
conditional_builder = ConditionalBuilder.instantiate(condition, shell_builder)
jb.add_builder(conditional_builder)
# Get a fresh copy of our job to ensure we have an up to date
# copy of the config.xml for the job
async_assert(lambda: jk.find_job(expected_job_name).builders)
builders = jk.find_job(expected_job_name).builders
# Make sure the builder was correctly configured
assert builders[0].condition is not None
assert isinstance(builders[0].condition, NeverRun)
assert builders[0].condition.get_friendly_name() == "never"
# Finally, just to be sure our build actually did something relevant
# we make sure the output from our shell command appears in the
# build output for a build (ie: to ensure the conditional build step
# actually ran)
jb.start_build()
async_assert(lambda: jb.last_build)
assert expected_output not in jb.last_build.console_output
示例14: test_multiple_upstream_jobs_recursive
def test_multiple_upstream_jobs_recursive(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
parent_job_name = "test_multiple_upstream_jobs_recursive1"
jb = jk.create_job(parent_job_name, FreestyleJob)
with clean_job(jb):
expected_name1 = "test_multiple_upstream_jobs_recursive2"
jb2 = jk.create_job(expected_name1, FreestyleJob)
with clean_job(jb2):
expected_name2 = "test_multiple_upstream_jobs_recursive3"
jb3 = jk.create_job(expected_name2, FreestyleJob)
with clean_job(jb3):
publisher1 = BuildTriggerPublisher.instantiate([expected_name1])
jb.add_publisher(publisher1)
publisher2 = BuildTriggerPublisher.instantiate([expected_name2])
jb2.add_publisher(publisher2)
async_assert(lambda: len(jb3.all_upstream_jobs) == 2)
res = jb3.all_upstream_jobs
all_names = [parent_job_name, expected_name1]
assert isinstance(res, list)
assert len(res) == 2
assert res[0].name in all_names
assert res[1].name in all_names
assert isinstance(res[0], FreestyleJob)
assert isinstance(res[1], FreestyleJob)
示例15: test_prepare_shutdown
def test_prepare_shutdown(jenkins_env):
jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
try:
jk.prepare_shutdown()
assert jk.is_shutting_down
finally:
jk.cancel_shutdown()