diff --git a/tests/fixtures/config/job-pause/git/org_project4/README b/tests/fixtures/config/job-pause/git/org_project4/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/job-pause/git/org_project4/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/job-pause/git/org_project4/playbooks/after-compile.yaml b/tests/fixtures/config/job-pause/git/org_project4/playbooks/after-compile.yaml new file mode 100644 index 0000000000..939b79247b --- /dev/null +++ b/tests/fixtures/config/job-pause/git/org_project4/playbooks/after-compile.yaml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - name: Good + debug: + msg: This shall not fail diff --git a/tests/fixtures/config/job-pause/git/org_project4/playbooks/compile-fail.yaml b/tests/fixtures/config/job-pause/git/org_project4/playbooks/compile-fail.yaml new file mode 100644 index 0000000000..517ad6c314 --- /dev/null +++ b/tests/fixtures/config/job-pause/git/org_project4/playbooks/compile-fail.yaml @@ -0,0 +1,12 @@ +- hosts: all + tasks: + - name: Pause and let child run + zuul_return: + data: + zuul: + pause: true + + # Fail the playbook AFTER we have set zuul_return + - name: Fail + fail: + msg: This shall fail diff --git a/tests/fixtures/config/job-pause/git/org_project4/zuul.yaml b/tests/fixtures/config/job-pause/git/org_project4/zuul.yaml new file mode 100644 index 0000000000..bb17f0530a --- /dev/null +++ b/tests/fixtures/config/job-pause/git/org_project4/zuul.yaml @@ -0,0 +1,15 @@ +- job: + name: compile-fail + run: playbooks/compile-fail.yaml + +- job: + name: after-compile + run: playbooks/after-compile.yaml + +- project: + check: + jobs: + - compile-fail + - after-compile: + dependencies: + - compile-fail diff --git a/tests/fixtures/config/job-pause/main.yaml b/tests/fixtures/config/job-pause/main.yaml index 8f7dd3ace0..9b4d1b940c 100644 --- a/tests/fixtures/config/job-pause/main.yaml +++ b/tests/fixtures/config/job-pause/main.yaml @@ -7,3 +7,4 @@ - org/project - org/project2 - org/project3 + - org/project4 diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py index dee13417bb..76af76d349 100644 --- a/tests/unit/test_v3.py +++ b/tests/unit/test_v3.py @@ -5531,6 +5531,22 @@ class TestJobPause(AnsibleZuulTestCase): dict(name='test2-after-compile1', result='SUCCESS', changes='1,1'), ], ordered=False) + def test_job_pause_fail(self): + """ + Test that only succeeding jobs are allowed to pause. + + compile-fail + +--> after-compile + """ + A = self.fake_gerrit.addFakeChange('org/project4', 'master', 'A') + + self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) + self.waitUntilSettled() + + self.assertHistory([ + dict(name='compile-fail', result='FAILURE', changes='1,1'), + ]) + def test_job_node_failure_resume(self): self.wait_timeout = 120 diff --git a/zuul/executor/server.py b/zuul/executor/server.py index 1618809db1..4483487567 100644 --- a/zuul/executor/server.py +++ b/zuul/executor/server.py @@ -1418,7 +1418,7 @@ class AnsibleJob(object): # check if we need to pause here result_data = self.getResultData() pause = result_data.get('zuul', {}).get('pause') - if pause: + if success and pause: self.pause() if self.aborted: return 'ABORTED'