Commit ec59bf70 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'e2300-lm-template' into 'master'

Migrate License-Scanning CI template to rules syntax

See merge request gitlab-org/gitlab!30784
parents 14827b36 1f7c7e6b
---
title: Migrate License-Scanning CI template to rules syntax
merge_request: 30784
author:
type: changed
# frozen_string_literal: true
require 'spec_helper'
describe 'License-Scanning.gitlab-ci.yml' do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('License-Scanning') }
describe 'the created pipeline' do
let(:user) { create(:admin) }
let(:default_branch) { 'master' }
let(:project) { create(:project, :custom_repo, files: { 'README.txt' => '' }) }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: 'master' ) }
let(:pipeline) { service.execute!(:push) }
let(:build_names) { pipeline.builds.pluck(:name) }
before do
stub_ci_pipeline_yaml_file(template.content)
allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
allow(project).to receive(:default_branch).and_return(default_branch)
end
context 'when project has no license' do
it 'includes no jobs' do
expect { pipeline }.to raise_error(Ci::CreatePipelineService::CreateError)
end
end
context 'when project has Ultimate license' do
let(:license) { create(:license, plan: License::ULTIMATE_PLAN) }
before do
allow(License).to receive(:current).and_return(license)
end
context 'by default' do
it 'includes job' do
expect(build_names).to match_array(%w[license_scanning])
end
end
context 'when LICENSE_MANAGEMENT_DISABLED=1' do
before do
create(:ci_variable, project: project, key: 'LICENSE_MANAGEMENT_DISABLED', value: '1')
end
it 'includes no jobs' do
expect { pipeline }.to raise_error(Ci::CreatePipelineService::CreateError)
end
end
end
end
end
......@@ -27,11 +27,8 @@ license_scanning:
reports:
license_scanning: $LM_REPORT_FILE
dependencies: []
only:
refs:
- branches
variables:
- $GITLAB_FEATURES =~ /\blicense_scanning\b/
except:
variables:
- $LICENSE_MANAGEMENT_DISABLED
rules:
- if: $LICENSE_MANAGEMENT_DISABLED
when: never
- if: $CI_COMMIT_BRANCH &&
$GITLAB_FEATURES =~ /\blicense_scanning\b/
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