Commit 36e9d9f3 authored by Stan Hu's avatar Stan Hu

Merge branch 'add-kubeconfig-condition-to-auto-devops' into 'master'

Run Auto DevOps jobs when KUBECONFIG is present

See merge request gitlab-org/gitlab!73708
parents a63c811b fb533898
...@@ -19,12 +19,13 @@ RSpec.describe 'Jobs/Browser-Performance-Testing.gitlab-ci.yml' do ...@@ -19,12 +19,13 @@ RSpec.describe 'Jobs/Browser-Performance-Testing.gitlab-ci.yml' do
end end
describe 'the created pipeline' do describe 'the created pipeline' do
let_it_be(:project) do let_it_be(:project_with_ci_kubernetes_active) do
create(:project, :repository, variables: [ create(:project, :repository, variables: [
build(:ci_variable, key: 'CI_KUBERNETES_ACTIVE', value: 'true') build(:ci_variable, key: 'CI_KUBERNETES_ACTIVE', value: 'true')
]) ])
end end
let(:project) { project_with_ci_kubernetes_active }
let(:user) { project.owner } let(:user) { project.owner }
let(:default_branch) { 'master' } let(:default_branch) { 'master' }
let(:pipeline_ref) { default_branch } let(:pipeline_ref) { default_branch }
...@@ -46,6 +47,18 @@ RSpec.describe 'Jobs/Browser-Performance-Testing.gitlab-ci.yml' do ...@@ -46,6 +47,18 @@ RSpec.describe 'Jobs/Browser-Performance-Testing.gitlab-ci.yml' do
expect(pipeline.errors).to be_empty expect(pipeline.errors).to be_empty
end end
context 'when variable is KUBECONFIG and not CI_KUBERNETES_ACTIVE' do
let_it_be(:project_with_kubeconfig) do
create(:project, :repository, variables: [
build(:ci_variable, key: 'KUBECONFIG', value: 'true')
])
end
it 'is present' do
expect(build_names).to include('browser_performance')
end
end
shared_examples_for 'browser_performance job on tag or branch' do shared_examples_for 'browser_performance job on tag or branch' do
it 'by default' do it 'by default' do
expect(build_names).to include('browser_performance') expect(build_names).to include('browser_performance')
......
...@@ -22,12 +22,13 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do ...@@ -22,12 +22,13 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do
end end
describe 'the created pipeline' do describe 'the created pipeline' do
let_it_be_with_refind(:project) do let_it_be_with_refind(:project_with_ci_kubernetes_active) do
create(:project, :repository, variables: [ create(:project, :repository, variables: [
build(:ci_variable, key: 'CI_KUBERNETES_ACTIVE', value: 'true') build(:ci_variable, key: 'CI_KUBERNETES_ACTIVE', value: 'true')
]) ])
end end
let(:project) { project_with_ci_kubernetes_active }
let(:user) { project.owner } let(:user) { project.owner }
let(:default_branch) { 'master' } let(:default_branch) { 'master' }
let(:pipeline_ref) { default_branch } let(:pipeline_ref) { default_branch }
...@@ -61,12 +62,9 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do ...@@ -61,12 +62,9 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do
end end
context 'default branch' do context 'default branch' do
it 'includes the DAST environment jobs by default' do it 'includes the DAST environment jobs by default', :aggregate_failures do
expect(build_names).to include('dast_environment_deploy') expect(build_names).to include('dast_environment_deploy')
expect(build_names).to include('stop_dast_environment') expect(build_names).to include('stop_dast_environment')
end
it 'always runs the cleanup job' do
expect(pipeline.builds.find_by(name: 'stop_dast_environment').when).to eq('always') expect(pipeline.builds.find_by(name: 'stop_dast_environment').when).to eq('always')
end end
...@@ -76,6 +74,20 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do ...@@ -76,6 +74,20 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do
expect(build_names).not_to include('dast_environment_deploy') expect(build_names).not_to include('dast_environment_deploy')
expect(build_names).not_to include('stop_dast_environment') expect(build_names).not_to include('stop_dast_environment')
end end
context 'when KUBECONFIG and not CI_KUBERNETES_ACTIVE' do
let(:project) do
create(:project, :repository, variables: [
build(:ci_variable, key: 'KUBECONFIG', value: 'true')
])
end
it 'includes the DAST environment jobs', :aggregate_failures do
expect(build_names).to include('dast_environment_deploy')
expect(build_names).to include('stop_dast_environment')
expect(pipeline.builds.find_by(name: 'stop_dast_environment').when).to eq('always')
end
end
end end
context 'on another branch' do context 'on another branch' do
......
...@@ -54,34 +54,17 @@ RSpec.describe 'DAST.gitlab-ci.yml' do ...@@ -54,34 +54,17 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
context 'when project has Ultimate license' do context 'when project has Ultimate license' do
let(:license) { build(:license, plan: License::ULTIMATE_PLAN) } let(:license) { build(:license, plan: License::ULTIMATE_PLAN) }
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
before do before do
allow(License).to receive(:current).and_return(license) allow(License).to receive(:current).and_return(license)
end end
context 'by default' do it 'includes job' do
before do expect(build_names).to match_array(%w[dast])
allow(cluster).to receive(:active?).and_return(true)
end
it 'includes job' do
expect(build_names).to match_array(%w[dast])
end
end
context 'when cluster is not active' do
context 'by default' do
it 'includes dast job' do
expect(build_names).to match_array(%w[dast])
end
end
end end
context 'when DAST_DISABLED=1' do context 'when DAST_DISABLED=1' do
before do before do
allow(cluster).to receive(:active?).and_return(true)
create(:ci_variable, project: project, key: 'DAST_DISABLED', value: '1') create(:ci_variable, project: project, key: 'DAST_DISABLED', value: '1')
end end
...@@ -92,8 +75,6 @@ RSpec.describe 'DAST.gitlab-ci.yml' do ...@@ -92,8 +75,6 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
context 'when DAST_DISABLED_FOR_DEFAULT_BRANCH=1' do context 'when DAST_DISABLED_FOR_DEFAULT_BRANCH=1' do
before do before do
allow(cluster).to receive(:active?).and_return(true)
create(:ci_variable, project: project, key: 'DAST_DISABLED_FOR_DEFAULT_BRANCH', value: '1') create(:ci_variable, project: project, key: 'DAST_DISABLED_FOR_DEFAULT_BRANCH', value: '1')
end end
...@@ -118,8 +99,6 @@ RSpec.describe 'DAST.gitlab-ci.yml' do ...@@ -118,8 +99,6 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
context 'when REVIEW_DISABLED=true' do context 'when REVIEW_DISABLED=true' do
before do before do
allow(cluster).to receive(:active?).and_return(true)
create(:ci_variable, project: project, key: 'REVIEW_DISABLED', value: 'true') create(:ci_variable, project: project, key: 'REVIEW_DISABLED', value: 'true')
end end
......
...@@ -63,13 +63,11 @@ RSpec.describe 'DAST.latest.gitlab-ci.yml' do ...@@ -63,13 +63,11 @@ RSpec.describe 'DAST.latest.gitlab-ci.yml' do
end end
context 'when project has cluster' do context 'when project has cluster' do
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } before do
create(:cluster, :project, :provided_by_gcp, projects: [project])
end
context 'by default' do context 'by default' do
before do
allow(cluster).to receive(:active?).and_return(true)
end
include_examples 'includes no jobs' include_examples 'includes no jobs'
end end
...@@ -78,7 +76,6 @@ RSpec.describe 'DAST.latest.gitlab-ci.yml' do ...@@ -78,7 +76,6 @@ RSpec.describe 'DAST.latest.gitlab-ci.yml' do
before do before do
allow(License).to receive(:current).and_return(license) allow(License).to receive(:current).and_return(license)
allow(cluster).to receive(:active?).and_return(true)
end end
context 'when no specification provided' do context 'when no specification provided' do
...@@ -87,91 +84,85 @@ RSpec.describe 'DAST.latest.gitlab-ci.yml' do ...@@ -87,91 +84,85 @@ RSpec.describe 'DAST.latest.gitlab-ci.yml' do
end end
end end
context 'when cluster is not active' do context 'by default' do
context 'by default' do include_examples 'includes no jobs'
include_examples 'includes no jobs' end
context 'when DAST_WEBSITE is present' do
before do
create(:ci_variable, project: project, key: 'DAST_WEBSITE', value: 'http://example.com')
end end
context 'when DAST_WEBSITE is present' do include_examples 'includes dast job'
before do end
create(:ci_variable, project: project, key: 'DAST_WEBSITE', value: 'http://example.com')
end
include_examples 'includes dast job' context 'when DAST_API_SPECIFICATION is present' do
before do
create(:ci_variable, project: project, key: 'DAST_API_SPECIFICATION', value: 'http://my.api/api-specification.yml')
end end
context 'when DAST_API_SPECIFICATION is present' do include_examples 'includes dast job'
before do end
create(:ci_variable, project: project, key: 'DAST_API_SPECIFICATION', value: 'http://my.api/api-specification.yml')
end
include_examples 'includes dast job' context 'when project has Ultimate license' do
end let(:license) { build(:license, plan: License::ULTIMATE_PLAN) }
context 'when project has Ultimate license' do before do
let(:license) { build(:license, plan: License::ULTIMATE_PLAN) } allow(License).to receive(:current).and_return(license)
end
context 'when project has cluster' do
before do before do
allow(License).to receive(:current).and_return(license) create(:cluster, :project, :provided_by_gcp, projects: [project])
end end
context 'when project has cluster' do context 'when DAST_DISABLED=1' do
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } before do
create(:ci_variable, project: project, key: 'DAST_DISABLED', value: '1')
end
context 'when DAST_DISABLED=1' do include_examples 'includes no jobs'
before do end
allow(cluster).to receive(:active?).and_return(true)
create(:ci_variable, project: project, key: 'DAST_DISABLED', value: '1') context 'when DAST_DISABLED_FOR_DEFAULT_BRANCH=1' do
end before do
create(:ci_variable, project: project, key: 'DAST_DISABLED_FOR_DEFAULT_BRANCH', value: '1')
end
context 'when on default branch' do
include_examples 'includes no jobs' include_examples 'includes no jobs'
end end
context 'when DAST_DISABLED_FOR_DEFAULT_BRANCH=1' do context 'when on feature branch' do
before do let(:pipeline_branch) { 'patch-1' }
allow(cluster).to receive(:active?).and_return(true)
create(:ci_variable, project: project, key: 'DAST_DISABLED_FOR_DEFAULT_BRANCH', value: '1') before do
project.repository.create_branch(pipeline_branch, default_branch)
end end
context 'when on default branch' do it 'includes dast job' do
include_examples 'includes no jobs' expect(build_names).to match_array(%w[dast])
end end
end
end
context 'when on feature branch' do context 'when REVIEW_DISABLED=true' do
let(:pipeline_branch) { 'patch-1' } before do
create(:ci_variable, project: project, key: 'REVIEW_DISABLED', value: 'true')
before do
project.repository.create_branch(pipeline_branch, default_branch)
end
it 'includes dast job' do
expect(build_names).to match_array(%w[dast])
end
end
end end
context 'when REVIEW_DISABLED=true' do context 'when on default branch' do
before do include_examples 'includes dast job'
allow(cluster).to receive(:active?).and_return(true) end
create(:ci_variable, project: project, key: 'REVIEW_DISABLED', value: 'true') context 'when on feature branch' do
end let(:pipeline_branch) { 'patch-1' }
context 'when on default branch' do before do
include_examples 'includes dast job' project.repository.create_branch(pipeline_branch, default_branch)
end end
context 'when on feature branch' do include_examples 'includes no jobs'
let(:pipeline_branch) { 'patch-1' }
before do
project.repository.create_branch(pipeline_branch, default_branch)
end
include_examples 'includes no jobs'
end
end end
end end
end end
......
...@@ -70,7 +70,7 @@ browser_performance: ...@@ -70,7 +70,7 @@ browser_performance:
reports: reports:
browser_performance: browser-performance.json browser_performance: browser-performance.json
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$BROWSER_PERFORMANCE_DISABLED' - if: '$BROWSER_PERFORMANCE_DISABLED'
when: never when: never
......
...@@ -70,7 +70,7 @@ browser_performance: ...@@ -70,7 +70,7 @@ browser_performance:
reports: reports:
browser_performance: browser-performance.json browser_performance: browser-performance.json
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$BROWSER_PERFORMANCE_DISABLED' - if: '$BROWSER_PERFORMANCE_DISABLED'
when: never when: never
......
...@@ -9,6 +9,6 @@ cloud_formation: ...@@ -9,6 +9,6 @@ cloud_formation:
rules: rules:
- if: '($AUTO_DEVOPS_PLATFORM_TARGET != "EC2") || ($AUTO_DEVOPS_PLATFORM_TARGET != "ECS")' - if: '($AUTO_DEVOPS_PLATFORM_TARGET != "EC2") || ($AUTO_DEVOPS_PLATFORM_TARGET != "ECS")'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
...@@ -30,7 +30,7 @@ dast_environment_deploy: ...@@ -30,7 +30,7 @@ dast_environment_deploy:
- if: $DAST_WEBSITE # we don't need to create a review app if a URL is already given - if: $DAST_WEBSITE # we don't need to create a review app if a URL is already given
when: never when: never
- if: $CI_COMMIT_BRANCH && - if: $CI_COMMIT_BRANCH &&
$CI_KUBERNETES_ACTIVE && ($CI_KUBERNETES_ACTIVE || $KUBECONFIG) &&
$GITLAB_FEATURES =~ /\bdast\b/ $GITLAB_FEATURES =~ /\bdast\b/
stop_dast_environment: stop_dast_environment:
...@@ -54,6 +54,6 @@ stop_dast_environment: ...@@ -54,6 +54,6 @@ stop_dast_environment:
- if: $DAST_WEBSITE # we don't need to create a review app if a URL is already given - if: $DAST_WEBSITE # we don't need to create a review app if a URL is already given
when: never when: never
- if: $CI_COMMIT_BRANCH && - if: $CI_COMMIT_BRANCH &&
$CI_KUBERNETES_ACTIVE && ($CI_KUBERNETES_ACTIVE || $KUBECONFIG) &&
$GITLAB_FEATURES =~ /\bdast\b/ $GITLAB_FEATURES =~ /\bdast\b/
when: always when: always
...@@ -25,7 +25,7 @@ review: ...@@ -25,7 +25,7 @@ review:
paths: [environment_url.txt, tiller.log] paths: [environment_url.txt, tiller.log]
when: always when: always
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -47,7 +47,7 @@ stop_review: ...@@ -47,7 +47,7 @@ stop_review:
action: stop action: stop
allow_failure: true allow_failure: true
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -77,7 +77,7 @@ staging: ...@@ -77,7 +77,7 @@ staging:
name: staging name: staging
url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -105,7 +105,7 @@ canary: ...@@ -105,7 +105,7 @@ canary:
rules: rules:
- if: '$CI_DEPLOY_FREEZE != null' - if: '$CI_DEPLOY_FREEZE != null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -137,7 +137,7 @@ production: ...@@ -137,7 +137,7 @@ production:
rules: rules:
- if: '$CI_DEPLOY_FREEZE != null' - if: '$CI_DEPLOY_FREEZE != null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$STAGING_ENABLED' - if: '$STAGING_ENABLED'
when: never when: never
...@@ -155,7 +155,7 @@ production_manual: ...@@ -155,7 +155,7 @@ production_manual:
rules: rules:
- if: '$CI_DEPLOY_FREEZE != null' - if: '$CI_DEPLOY_FREEZE != null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$INCREMENTAL_ROLLOUT_ENABLED' - if: '$INCREMENTAL_ROLLOUT_ENABLED'
when: never when: never
...@@ -194,7 +194,7 @@ production_manual: ...@@ -194,7 +194,7 @@ production_manual:
rules: rules:
- if: '$CI_DEPLOY_FREEZE != null' - if: '$CI_DEPLOY_FREEZE != null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$INCREMENTAL_ROLLOUT_MODE == "timed"' - if: '$INCREMENTAL_ROLLOUT_MODE == "timed"'
when: never when: never
...@@ -209,7 +209,7 @@ production_manual: ...@@ -209,7 +209,7 @@ production_manual:
rules: rules:
- if: '$CI_DEPLOY_FREEZE != null' - if: '$CI_DEPLOY_FREEZE != null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$INCREMENTAL_ROLLOUT_MODE == "manual"' - if: '$INCREMENTAL_ROLLOUT_MODE == "manual"'
when: never when: never
......
...@@ -21,7 +21,7 @@ review: ...@@ -21,7 +21,7 @@ review:
paths: [environment_url.txt, tiller.log] paths: [environment_url.txt, tiller.log]
when: always when: always
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -42,7 +42,7 @@ stop_review: ...@@ -42,7 +42,7 @@ stop_review:
action: stop action: stop
allow_failure: true allow_failure: true
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -71,7 +71,7 @@ staging: ...@@ -71,7 +71,7 @@ staging:
name: staging name: staging
url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -96,7 +96,7 @@ canary: ...@@ -96,7 +96,7 @@ canary:
name: production name: production
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -125,7 +125,7 @@ canary: ...@@ -125,7 +125,7 @@ canary:
production: production:
<<: *production_template <<: *production_template
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$STAGING_ENABLED' - if: '$STAGING_ENABLED'
when: never when: never
...@@ -141,7 +141,7 @@ production_manual: ...@@ -141,7 +141,7 @@ production_manual:
<<: *production_template <<: *production_template
allow_failure: false allow_failure: false
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$INCREMENTAL_ROLLOUT_ENABLED' - if: '$INCREMENTAL_ROLLOUT_ENABLED'
when: never when: never
...@@ -177,7 +177,7 @@ production_manual: ...@@ -177,7 +177,7 @@ production_manual:
resource_group: production resource_group: production
allow_failure: true allow_failure: true
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$INCREMENTAL_ROLLOUT_MODE == "timed"' - if: '$INCREMENTAL_ROLLOUT_MODE == "timed"'
when: never when: never
...@@ -190,7 +190,7 @@ production_manual: ...@@ -190,7 +190,7 @@ production_manual:
.timed_rollout_template: &timed_rollout_template .timed_rollout_template: &timed_rollout_template
<<: *rollout_template <<: *rollout_template
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$INCREMENTAL_ROLLOUT_MODE == "manual"' - if: '$INCREMENTAL_ROLLOUT_MODE == "manual"'
when: never when: never
......
...@@ -16,7 +16,7 @@ review_ec2: ...@@ -16,7 +16,7 @@ review_ec2:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "EC2"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "EC2"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$REVIEW_DISABLED' - if: '$REVIEW_DISABLED'
when: never when: never
...@@ -32,7 +32,7 @@ production_ec2: ...@@ -32,7 +32,7 @@ production_ec2:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "EC2"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "EC2"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
......
...@@ -42,7 +42,7 @@ review_ecs: ...@@ -42,7 +42,7 @@ review_ecs:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$REVIEW_DISABLED' - if: '$REVIEW_DISABLED'
when: never when: never
...@@ -58,7 +58,7 @@ stop_review_ecs: ...@@ -58,7 +58,7 @@ stop_review_ecs:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$REVIEW_DISABLED' - if: '$REVIEW_DISABLED'
when: never when: never
...@@ -77,7 +77,7 @@ review_fargate: ...@@ -77,7 +77,7 @@ review_fargate:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$REVIEW_DISABLED' - if: '$REVIEW_DISABLED'
when: never when: never
...@@ -93,7 +93,7 @@ stop_review_fargate: ...@@ -93,7 +93,7 @@ stop_review_fargate:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$REVIEW_DISABLED' - if: '$REVIEW_DISABLED'
when: never when: never
...@@ -107,7 +107,7 @@ production_ecs: ...@@ -107,7 +107,7 @@ production_ecs:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -118,7 +118,7 @@ production_fargate: ...@@ -118,7 +118,7 @@ production_fargate:
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE' - if: '$CI_KUBERNETES_ACTIVE || $KUBECONFIG'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
rules: rules:
- if: '$MIGRATE_HELM_2TO3 != "true"' - if: '$MIGRATE_HELM_2TO3 != "true"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -89,7 +89,7 @@ review:helm-2to3:cleanup: ...@@ -89,7 +89,7 @@ review:helm-2to3:cleanup:
rules: rules:
- if: '$MIGRATE_HELM_2TO3 != "true" && $CLEANUP_HELM_2TO3 == null' - if: '$MIGRATE_HELM_2TO3 != "true" && $CLEANUP_HELM_2TO3 == null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -104,7 +104,7 @@ review:helm-2to3:cleanup: ...@@ -104,7 +104,7 @@ review:helm-2to3:cleanup:
rules: rules:
- if: '$MIGRATE_HELM_2TO3 != "true"' - if: '$MIGRATE_HELM_2TO3 != "true"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -119,7 +119,7 @@ staging:helm-2to3:cleanup: ...@@ -119,7 +119,7 @@ staging:helm-2to3:cleanup:
rules: rules:
- if: '$MIGRATE_HELM_2TO3 != "true" && $CLEANUP_HELM_2TO3 == null' - if: '$MIGRATE_HELM_2TO3 != "true" && $CLEANUP_HELM_2TO3 == null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never when: never
...@@ -132,7 +132,7 @@ staging:helm-2to3:cleanup: ...@@ -132,7 +132,7 @@ staging:helm-2to3:cleanup:
rules: rules:
- if: '$MIGRATE_HELM_2TO3 != "true"' - if: '$MIGRATE_HELM_2TO3 != "true"'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: manual when: manual
...@@ -145,7 +145,7 @@ production:helm-2to3:cleanup: ...@@ -145,7 +145,7 @@ production:helm-2to3:cleanup:
rules: rules:
- if: '$MIGRATE_HELM_2TO3 != "true" && $CLEANUP_HELM_2TO3 == null' - if: '$MIGRATE_HELM_2TO3 != "true" && $CLEANUP_HELM_2TO3 == null'
when: never when: never
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: manual when: manual
...@@ -23,7 +23,7 @@ load_performance: ...@@ -23,7 +23,7 @@ load_performance:
reports: reports:
load_performance: load-performance.json load_performance: load-performance.json
rules: rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""' - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never when: never
- if: '$LOAD_PERFORMANCE_DISABLED' - if: '$LOAD_PERFORMANCE_DISABLED'
when: never when: never
......
...@@ -51,7 +51,7 @@ dast: ...@@ -51,7 +51,7 @@ dast:
$REVIEW_DISABLED $REVIEW_DISABLED
when: never when: never
- if: $CI_COMMIT_BRANCH && - if: $CI_COMMIT_BRANCH &&
$CI_KUBERNETES_ACTIVE && ($CI_KUBERNETES_ACTIVE || $KUBECONFIG) &&
$GITLAB_FEATURES =~ /\bdast\b/ $GITLAB_FEATURES =~ /\bdast\b/
- if: $CI_COMMIT_BRANCH && - if: $CI_COMMIT_BRANCH &&
$GITLAB_FEATURES =~ /\bdast\b/ $GITLAB_FEATURES =~ /\bdast\b/
...@@ -52,7 +52,7 @@ dast: ...@@ -52,7 +52,7 @@ dast:
$DAST_API_SPECIFICATION == null $DAST_API_SPECIFICATION == null
when: never when: never
- if: $CI_COMMIT_BRANCH && - if: $CI_COMMIT_BRANCH &&
$CI_KUBERNETES_ACTIVE && ($CI_KUBERNETES_ACTIVE || $KUBECONFIG) &&
$GITLAB_FEATURES =~ /\bdast\b/ $GITLAB_FEATURES =~ /\bdast\b/
- if: $CI_COMMIT_BRANCH && - if: $CI_COMMIT_BRANCH &&
$DAST_WEBSITE $DAST_WEBSITE
......
...@@ -27,9 +27,9 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do ...@@ -27,9 +27,9 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do
end end
describe 'the created pipeline' do describe 'the created pipeline' do
let(:project) { create(:project, :repository) } let_it_be(:project, refind: true) { create(:project, :repository) }
let(:user) { project.owner }
let(:user) { project.owner }
let(:default_branch) { 'master' } let(:default_branch) { 'master' }
let(:pipeline_ref) { default_branch } let(:pipeline_ref) { default_branch }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_ref) } let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_ref) }
...@@ -43,23 +43,23 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do ...@@ -43,23 +43,23 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do
allow(project).to receive(:default_branch).and_return(default_branch) allow(project).to receive(:default_branch).and_return(default_branch)
end end
context 'with no cluster' do context 'with no cluster or agent' do
it 'does not create any kubernetes deployment jobs' do it 'does not create any kubernetes deployment jobs' do
expect(build_names).to eq %w(placeholder) expect(build_names).to eq %w(placeholder)
end end
end end
context 'with only a disabled cluster' do context 'with only a disabled cluster' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp, enabled: false, projects: [project]) } before do
create(:cluster, :project, :provided_by_gcp, enabled: false, projects: [project])
end
it 'does not create any kubernetes deployment jobs' do it 'does not create any kubernetes deployment jobs' do
expect(build_names).to eq %w(placeholder) expect(build_names).to eq %w(placeholder)
end end
end end
context 'with an active cluster' do shared_examples_for 'pipeline with deployment jobs' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
context 'on master' do context 'on master' do
it 'by default' do it 'by default' do
expect(build_names).to include('production') expect(build_names).to include('production')
...@@ -218,5 +218,21 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do ...@@ -218,5 +218,21 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do
end end
end end
end end
context 'with an agent' do
before do
create(:cluster_agent, project: project)
end
it_behaves_like 'pipeline with deployment jobs'
end
context 'with a cluster' do
before do
create(:cluster, :project, :provided_by_gcp, projects: [project])
end
it_behaves_like 'pipeline with deployment jobs'
end
end end
end end
...@@ -148,9 +148,7 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -148,9 +148,7 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do
it_behaves_like 'no Kubernetes deployment job' it_behaves_like 'no Kubernetes deployment job'
end end
context 'when the project has an active cluster' do shared_examples 'pipeline with Kubernetes jobs' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
describe 'deployment-related builds' do describe 'deployment-related builds' do
context 'on default branch' do context 'on default branch' do
it 'does not include rollout jobs besides production' do it 'does not include rollout jobs besides production' do
...@@ -233,6 +231,22 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -233,6 +231,22 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do
end end
end end
end end
context 'when a cluster is attached' do
before do
create(:cluster, :project, :provided_by_gcp, projects: [project])
end
it_behaves_like 'pipeline with Kubernetes jobs'
end
context 'when project has an Agent is present' do
before do
create(:cluster_agent, project: project)
end
it_behaves_like 'pipeline with Kubernetes jobs'
end
end end
describe 'buildpack detection' do describe 'buildpack detection' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment