Class: LabClient::Generator::Environments

Inherits:
GroupTemplateHelper show all
Defined in:
lib/labclient/generator/templates/environments.rb

Overview

Child and other Trigger Examples docs.gitlab.com/ee/ci/yaml/#trigger

Instance Attribute Summary

Attributes inherited from GroupTemplateHelper

#group_name, #group_path, #group_suffix, #project_name

Attributes inherited from TemplateHelper

#client, #opts

Instance Method Summary collapse

Methods inherited from GroupTemplateHelper

#generate_group, #run!, #setup

Methods included from Names

#create_file, #gen_description, #gen_groups, #gen_people, #gen_projects, #generate_names

Methods inherited from TemplateHelper

#initialize, #inspect, #setup

Constructor Details

This class inherits a constructor from LabClient::Generator::TemplateHelper

Instance Method Details

#on_stop_yamlObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/labclient/generator/templates/environments.rb', line 21

def on_stop_yaml
  <<~YAML
    image: busybox:latest

    build:
      stage: build
      script:
        - echo "Build on both master and branches"

    branch-review:
      stage: deploy
      environment:
        name: ${CI_COMMIT_REF_NAME}
        on_stop: review-teardown
      script:
        - echo "branch-review"
      only:
        - branches
      except:
        - master

    review-teardown:
      stage: deploy
      when: manual
      variables:
        GIT_STRATEGY: none
      environment:
        name: ${CI_COMMIT_REF_NAME}
        action: stop
      script:
        - echo "review-teardown"
      only:
        - branches
      except:
        - master
  YAML
end

#setup_master_branch_environment_on_stopObject

rubocop:disable Metrics/MethodLength



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/labclient/generator/templates/environments.rb', line 60

def setup_master_branch_environment_on_stop
  project = @group.project_create(
    name: 'On Stop',
    description: 'Environments created on non-master branches, stopped on merge',
    auto_devops_enabled: false,
    only_allow_merge_if_pipeline_succeeds: true
  )

  # Create Parent
  project.file_create('README.md', create_file("# #{project.name}"))

  # # Create Branch
  project.branch_create(branch: :branch, ref: :master)

  # Create Branch Files
  project.file_create('.gitlab-ci.yml', create_file(on_stop_yaml, :branch))

  # Create Merge Request
  merge_request = project.merge_request_create(
    title: 'Merge Test Branch!',
    source_branch: :branch,
    target_branch: :master
  )

  # Wait for Merge
  merge_request.wait_for_merge_status

  # Merge
  merge_request.accept(
    should_remove_source_branch: true,
    merge_when_pipeline_succeeds: true
  )

  @projects.push project
end