1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
58
59
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# frozen_string_literal: true
module QA
RSpec.describe 'Verify', :runner, product_group: :pipeline_security do
describe "Unlocking job artifacts across pipelines" do
let(:executor) { "qa-runner-#{Faker::Alphanumeric.alphanumeric(number: 8)}" }
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'unlock-job-artifacts-project'
end
end
let!(:runner) do
Resource::ProjectRunner.fabricate! do |runner|
runner.project = project
runner.name = executor
runner.tags = [executor]
end
end
before do
Flow::Login.sign_in
project.visit!
end
after do
runner.remove_via_api!
end
context 'when latest pipeline is successful' do
before do
add_ci_file(job_name: 'job_1', script: 'echo test')
Flow::Pipeline.wait_for_latest_pipeline(status: 'passed')
end
it 'unlocks job artifacts from previous successful pipeline',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/394807' do
find_job('job_1').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_locked_artifact
end
update_ci_file(job_name: 'job_2', script: 'echo test')
Flow::Pipeline.wait_for_latest_pipeline(status: 'passed')
find_job('job_2').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_locked_artifact
end
find_job('job_1').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_unlocked_artifact
end
end
end
context 'when latest pipeline failed' do
before do
add_ci_file(job_name: 'successful_job_1', script: 'echo test')
Flow::Pipeline.wait_for_latest_pipeline(status: 'passed')
end
it 'keeps job artifacts from latest failed pipelines and from latest successful pipeline',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/394808',
quarantine: {
issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/266958',
type: :bug
} do
update_ci_file(job_name: 'failed_job_1', script: 'exit 1')
Flow::Pipeline.wait_for_latest_pipeline(status: 'failed')
update_ci_file(job_name: 'failed_job_2', script: 'exit 2')
Flow::Pipeline.wait_for_latest_pipeline(status: 'failed')
find_job('failed_job_2').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_locked_artifact
end
find_job('failed_job_1').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_unlocked_artifact
end
find_job('successful_job_1').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_locked_artifact
end
end
end
context 'when latest pipeline is blocked' do
before do
add_ci_file(job_name: 'successful_job_1', script: 'echo test')
Flow::Pipeline.wait_for_latest_pipeline(status: 'passed')
end
it 'keeps job artifacts from the latest blocked pipeline and from latest successful pipeline',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/395511',
quarantine: {
issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/387087',
type: :bug
} do
update_ci_with_manual_job(job_name: 'successful_job_with_manual_1', script: 'echo test')
Flow::Pipeline.wait_for_latest_pipeline(status: 'blocked')
update_ci_with_manual_job(job_name: 'successful_job_with_manual_2', script: 'echo test')
Flow::Pipeline.wait_for_latest_pipeline(status: 'blocked')
find_job('successful_job_with_manual_2').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_locked_artifact
end
find_job('successful_job_with_manual_1').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_unlocked_artifact
end
find_job('successful_job_1').visit!
Page::Project::Job::Show.perform do |job|
expect(job).to have_locked_artifact
end
end
end
private
def add_ci_file(job_name:, script:)
ci_file = ci_file_with_job_artifact(job_name, script)
original_pipeline_count = pipeline_count
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = "Set job #{job_name} script #{script}"
commit.add_files([ci_file])
end
wait_for_new_pipeline(original_pipeline_count)
end
def update_ci_file(job_name:, script:)
ci_file = ci_file_with_job_artifact(job_name, script)
original_pipeline_count = pipeline_count
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = "Set job #{job_name} script #{script}"
commit.update_files([ci_file])
end
wait_for_new_pipeline(original_pipeline_count)
end
def update_ci_with_manual_job(job_name:, script:)
ci_file = ci_file_with_manual_job(job_name, script)
original_pipeline_count = pipeline_count
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = "Set job #{job_name} script #{script}"
commit.update_files([ci_file])
end
wait_for_new_pipeline(original_pipeline_count)
end
def ci_file_with_job_artifact(job_name, script)
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
#{job_name}:
stage: test
tags: ["#{executor}"]
script: #{script}
artifacts:
paths: ['.gitlab-ci.yml']
when: always
YAML
}
end
def ci_file_with_manual_job(job_name, script)
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
#{job_name}:
stage: test
tags: ["#{executor}"]
script: #{script}
artifacts:
paths: ['.gitlab-ci.yml']
manual-job:
stage: test
tags: ["#{executor}"]
rules:
- when: manual
script: "echo 'this job is manual'"
artifacts:
paths: ['.gitlab-ci.yml']
YAML
}
end
def find_job(job_name)
Resource::Job.fabricate_via_api! do |job|
job.project = project
job.id = project.job_by_name(job_name)[:id]
end
end
def pipeline_count
project.pipelines.length
end
def wait_for_new_pipeline(original_pipeline_count)
QA::Runtime::Logger.info('Waiting for new pipeline to be created')
Support::Waiter.wait_until { pipeline_count > original_pipeline_count }
end
end
end
end
|