diff options
Diffstat (limited to 'qa/qa/specs/features/browser_ui/3_create/jenkins/jenkins_build_status_spec.rb')
-rw-r--r-- | qa/qa/specs/features/browser_ui/3_create/jenkins/jenkins_build_status_spec.rb | 177 |
1 files changed, 84 insertions, 93 deletions
diff --git a/qa/qa/specs/features/browser_ui/3_create/jenkins/jenkins_build_status_spec.rb b/qa/qa/specs/features/browser_ui/3_create/jenkins/jenkins_build_status_spec.rb index ea531d84634..4bfd253c992 100644 --- a/qa/qa/specs/features/browser_ui/3_create/jenkins/jenkins_build_status_spec.rb +++ b/qa/qa/specs/features/browser_ui/3_create/jenkins/jenkins_build_status_spec.rb @@ -1,8 +1,23 @@ # frozen_string_literal: true module QA - RSpec.describe 'Create', :requires_admin, :skip_live_env, quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/195179', type: :flaky } do + RSpec.describe 'Create', :requires_admin, :skip_live_env, except: { job: 'review-qa-*' } do describe 'Jenkins integration' do + let(:jenkins_server) { Service::DockerRun::Jenkins.new } + + let(:jenkins_client) do + Vendor::Jenkins::Client.new( + jenkins_server.host_name, + port: jenkins_server.port, + user: Runtime::Env.jenkins_admin_username, + password: Runtime::Env.jenkins_admin_password + ) + end + + let(:jenkins_project_name) { "gitlab_jenkins_#{SecureRandom.hex(5)}" } + + let(:connection_name) { 'gitlab-connection' } + let(:project_name) { "project_with_jenkins_#{SecureRandom.hex(4)}" } let(:project) do @@ -13,97 +28,82 @@ module QA end end - before do - jenkins_server = run_jenkins_server + let(:access_token) do + Runtime::Env.personal_access_token ||= fabricate_access_token + end - Vendor::Jenkins::Page::Base.host = jenkins_server.host_address + before do + toggle_local_requests(true) + jenkins_server.register! - Runtime::Env.personal_access_token ||= fabricate_personal_access_token + Support::Waiter.wait_until(max_duration: 30, reload_page: false, retry_on_exception: true) do + jenkins_client.ready? + end - allow_requests_to_local_networks + configure_gitlab_jenkins + end - setup_jenkins + after do + jenkins_server&.remove! + toggle_local_requests(false) end it 'integrates and displays build status for MR pipeline in GitLab', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347788' do - login_to_gitlab + setup_project_integration - setup_project_integration_with_jenkins + jenkins_integration = project.find_integration('jenkins') + expect(jenkins_integration).not_to be(nil), 'Jenkins integration did not save' + expect(jenkins_integration[:active]).to be(true), 'Jenkins integration is not active' - expect(page).to have_text("Jenkins settings saved and active.") + job = create_jenkins_job - QA::Support::Retrier.retry_on_exception do - Resource::Repository::ProjectPush.fabricate! do |push| - push.project = project - push.new_branch = false - push.file_name = "file_#{SecureRandom.hex(4)}.txt" - end - - Vendor::Jenkins::Page::LastJobConsole.perform do |job_console| - job_console.job_name = project_name + Resource::Repository::ProjectPush.fabricate! do |push| + push.project = project + push.new_branch = false + push.file_name = "file_#{SecureRandom.hex(4)}.txt" + end - job_console.visit! + Support::Waiter.wait_until(max_duration: 60, raise_on_failure: false, reload_page: false) do + job.status == :success + end - Support::Waiter.wait_until(sleep_interval: 2, reload_page: page) do - job_console.has_successful_build? && job_console.no_failed_status_update? - end - end + expect(job.status).to eql(:success), "Build failed or is not found: #{job.log}" - project.visit! + project.visit! - Flow::Pipeline.visit_latest_pipeline + Flow::Pipeline.visit_latest_pipeline - Page::Project::Pipeline::Show.perform do |show| - expect(show).to have_build('jenkins', status: :success, wait: 15) - end + Page::Project::Pipeline::Show.perform do |show| + expect(show).to have_build('jenkins', status: :success, wait: 15) end end - after do - remove_jenkins_server - end + private - def setup_jenkins - Vendor::Jenkins::Page::Login.perform do |login_page| - login_page.visit! - login_page.login - end - - token_description = "token-#{SecureRandom.hex(8)}" - - Vendor::Jenkins::Page::NewCredentials.perform do |new_credentials| - new_credentials.visit_and_set_gitlab_api_token(Runtime::Env.personal_access_token, token_description) - end - - Vendor::Jenkins::Page::Configure.perform do |configure| - configure.visit_and_setup_gitlab_connection(patch_host_name(Runtime::Scenario.gitlab_address, 'gitlab'), token_description) do - configure.click_test_connection - expect(configure).to have_success - end - end + def setup_project_integration + login_to_gitlab - Vendor::Jenkins::Page::NewJob.perform do |new_job| - new_job.visit_and_create_new_job_with_name(project_name) - end + project.visit! - Vendor::Jenkins::Page::ConfigureJob.perform do |configure_job| - configure_job.job_name = project_name - configure_job.configure(scm_url: patch_host_name(project.repository_http_location.git_uri, 'gitlab')) - end - end + Page::Project::Menu.perform(&:click_project) + Page::Project::Menu.perform(&:go_to_integrations_settings) + Page::Project::Settings::Integrations.perform(&:click_jenkins_ci_link) - def run_jenkins_server - Service::DockerRun::Jenkins.new.tap do |runner| - runner.pull - runner.register! + QA::Page::Project::Settings::Services::Jenkins.perform do |jenkins| + jenkins.setup_service_with( + jenkins_url: patch_host_name(jenkins_server.host_address, 'jenkins-server'), + project_name: jenkins_project_name, + username: jenkins_server.username, + password: jenkins_server.password + ) end end - def remove_jenkins_server - Service::DockerRun::Jenkins.new.remove! + def login_to_gitlab + Flow::Login.sign_in end - def fabricate_personal_access_token + def fabricate_access_token login_to_gitlab token = Resource::PersonalAccessToken.fabricate!.token @@ -111,8 +111,23 @@ module QA token end - def login_to_gitlab - Flow::Login.sign_in + def create_jenkins_job + jenkins_client.create_job jenkins_project_name do |job| + job.gitlab_connection = connection_name + job.description = 'Just a job' + job.repo_url = patch_host_name(project.repository_http_location.git_uri, 'gitlab') + job.shell_command = 'sleep 5' + end + end + + def configure_gitlab_jenkins + jenkins_client.configure_gitlab_plugin( + patch_host_name(Runtime::Scenario.gitlab_address, 'gitlab'), + connection_name: connection_name, + access_token: access_token, + read_timeout: 20, + connection_timeout: 10 + ) end def patch_host_name(host_name, container_name) @@ -122,32 +137,8 @@ module QA host_name.gsub('localhost', ip_address) end - def setup_project_integration_with_jenkins - project.visit! - - Page::Project::Menu.perform(&:click_project) - Page::Project::Menu.perform(&:go_to_integrations_settings) - Page::Project::Settings::Integrations.perform(&:click_jenkins_ci_link) - - QA::Page::Project::Settings::Services::Jenkins.perform do |jenkins| - jenkins.setup_service_with(jenkins_url: patch_host_name(Vendor::Jenkins::Page::Base.host, 'jenkins-server'), - project_name: project_name) - end - end - - def allow_requests_to_local_networks - Page::Main::Menu.perform(&:sign_out_if_signed_in) - Flow::Login.sign_in_as_admin - Page::Main::Menu.perform(&:go_to_admin_area) - Page::Admin::Menu.perform(&:go_to_network_settings) - - Page::Admin::Settings::Network.perform do |network| - network.expand_outbound_requests do |outbound_requests| - outbound_requests.allow_requests_to_local_network_from_services - end - end - - Page::Main::Menu.perform(&:sign_out) + def toggle_local_requests(on) + Runtime::ApplicationSettings.set_application_settings(allow_local_requests_from_web_hooks_and_services: on) end end end |