File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -225,9 +225,22 @@ def _test_job(lang_config):
225225
226226
227227def _deploy_job (args ):
228- """Kubernetes deploy job."""
228+ """Kubernetes deploy job, or a generic deploy stub when kubernetes is disabled ."""
229229 if not args .kubernetes :
230- return {}
230+ protected_branches = [b .strip () for b in args .branches .split ("," )]
231+ rules = [
232+ {"if" : f"$CI_COMMIT_BRANCH == \" { b } \" " , "when" : "manual" if b != protected_branches [0 ] else "on_success" }
233+ for b in protected_branches
234+ ]
235+ return {
236+ "deploy" : {
237+ "stage" : "deploy" ,
238+ "script" : [
239+ "echo \" Deploy stage — configure your deployment scripts here\" " ,
240+ ],
241+ "rules" : rules ,
242+ }
243+ }
231244
232245 protected_branches = [b .strip () for b in args .branches .split ("," )]
233246
@@ -298,7 +311,7 @@ def generate_pipeline(args, custom_values):
298311 if args .type in ("test" , "complete" ):
299312 pipeline .update (_test_job (lang_config ))
300313
301- if args .type in ( "deploy" , "complete" ) and args .kubernetes :
314+ if args .type == "deploy" or ( args . type == "complete" and args .kubernetes ) :
302315 pipeline .update (_deploy_job (args ))
303316
304317 pipeline .update (custom_values )
Original file line number Diff line number Diff line change @@ -619,7 +619,8 @@ def test_deploy_pipeline_no_kubernetes_empty_stages(self):
619619 """
620620 BUG-1: When type='deploy' and kubernetes=False, the generated
621621 pipeline has an empty stages list, which is invalid for GitLab CI.
622- Expected: at least one stage should be present even for non-k8s deploy.
622+ Expected: at least one stage should be present even for non-k8s deploy,
623+ and a deploy job stub must be present in the pipeline.
623624 """
624625 with tempfile .TemporaryDirectory () as tmp :
625626 out = os .path .join (tmp , ".gitlab-ci.yml" )
@@ -636,6 +637,10 @@ def test_deploy_pipeline_no_kubernetes_empty_stages(self):
636637 assert len (stages ) > 0 , (
637638 "Expected at least one stage in a deploy pipeline, got: {!r}" .format (stages )
638639 )
640+ # A deploy job stub must be present so the pipeline is valid
641+ assert "deploy" in data , (
642+ "Expected a deploy job in the pipeline, got keys: {!r}" .format (list (data .keys ()))
643+ )
639644
640645
641646# ===========================================================================
You can’t perform that action at this time.
0 commit comments