summaryrefslogtreecommitdiff
path: root/qa/qa/service/docker_run/jenkins.rb
blob: 88b69210382210c007a46df9d380068e655c5472 (plain)
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
# frozen_string_literal: true

module QA
  module Service
    module DockerRun
      class Jenkins < Base
        include Mixins::ThirdPartyDocker

        attr_reader :port

        def initialize
          @image = "#{third_party_repository}/jenkins:latest"
          @name = 'jenkins-server'
          @port = '8080'
          super
        end

        def network
          @network || 'test'
        end

        def username
          Runtime::Env.jenkins_admin_username
        end

        def password
          Runtime::Env.jenkins_admin_password
        end

        def host_address
          "http://#{host_name}:#{@port}"
        end

        def host_name
          return 'localhost' unless QA::Runtime::Env.running_in_ci?

          super
        end

        def register!
          authenticate_third_party

          command = <<~CMD.tr("\n", ' ')
            docker run -d --rm
            --network #{network}
            --hostname #{host_name}
            --name #{@name}
            --env JENKINS_USER=#{username}
            --env JENKINS_PASS=#{password}
            --publish #{@port}:8080
            --publish 50000:50000
            #{@image}
          CMD

          shell(command, mask_secrets: [password])

          wait_for_running
        end

        private

        def wait_for_running
          Support::Waiter.wait_until(max_duration: 10, reload_page: false, raise_on_failure: false) do
            running?
          end
        end
      end
    end
  end
end