Class: Danger::Jenkins

Inherits:
CI
  • Object
show all
Defined in:
lib/danger/ci_source/jenkins.rb

Overview

### CI Setup Ah Jenkins, so many memories. So, if you’re using Jenkins, you’re hosting your own environment.

#### GitHub You will want to be using the [GitHub pull request builder plugin](wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin) in order to ensure that you have the build environment set up for PR integration.

With that set up, you can edit your job to add ‘bundle exec danger` at the build action.

#### GitLab You will want to be using the [GitLab Plugin](github.com/jenkinsci/gitlab-plugin) in order to ensure that you have the build environment set up for MR integration.

With that set up, you can edit your job to add ‘bundle exec danger` at the build action.

### Token Setup

#### GitHub As you own the machine, it’s up to you to add the environment variable for the ‘DANGER_GITHUB_API_TOKEN`.

#### GitLab As you own the machine, it’s up to you to add the environment variable for the ‘DANGER_GITLAB_API_TOKEN`.

Instance Attribute Summary

Attributes inherited from CI

#pull_request_id, #repo_slug, #repo_url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CI

available_ci_sources, inherited, #supports?

Constructor Details

#initialize(env) ⇒ Jenkins

Returns a new instance of Jenkins.



44
45
46
47
48
49
50
# File 'lib/danger/ci_source/jenkins.rb', line 44

def initialize(env)
  self.repo_url = env["GIT_URL"]
  self.pull_request_id = self.class.pull_request_id(env)

  repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
  self.repo_slug = repo_matches[2] unless repo_matches.nil?
end

Class Method Details

.pull_request_id(env) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/danger/ci_source/jenkins.rb', line 52

def self.pull_request_id(env)
  if env["ghprbPullId"]
    env["ghprbPullId"]
  else
    env["gitlabMergeRequestId"]
  end
end

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/danger/ci_source/jenkins.rb', line 31

def self.validates_as_ci?(env)
  env.key? "JENKINS_URL"
end

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/danger/ci_source/jenkins.rb', line 35

def self.validates_as_pr?(env)
  id = pull_request_id(env)
  !id.nil? && !id.empty?
end

Instance Method Details

#supported_request_sourcesObject



40
41
42
# File 'lib/danger/ci_source/jenkins.rb', line 40

def supported_request_sources
  @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
end