|
@@ 72-83 (lines=12) @@
|
| 69 |
|
return $this->getGitlabUrl().'/api/v3/'; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
public function getGitlabProjectName() : string |
| 73 |
|
{ |
| 74 |
|
$projectName = $this->input->getOption('gitlab-project-name'); |
| 75 |
|
if ($projectName === null) { |
| 76 |
|
$projectDir = getenv('CI_PROJECT_DIR'); |
| 77 |
|
if ($projectDir === false) { |
| 78 |
|
throw new \RuntimeException('Could not find the Gitlab project name in the "CI_PROJECT_DIR" environment variable (usually set by Gitlab CI). Either set this environment variable or pass the project name via the --gitlab-project-name command line option.'); |
| 79 |
|
} |
| 80 |
|
$projectName = substr($projectDir, 8); |
| 81 |
|
} |
| 82 |
|
return $projectName; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
public function getCommitSha() : string |
| 86 |
|
{ |
|
@@ 85-100 (lines=16) @@
|
| 82 |
|
return $projectName; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
public function getCommitSha() : string |
| 86 |
|
{ |
| 87 |
|
$commitSha = $this->input->getOption('commit-sha'); |
| 88 |
|
|
| 89 |
|
if ($commitSha === null) { |
| 90 |
|
$commitSha = getenv('CI_COMMIT_SHA'); |
| 91 |
|
if ($commitSha === false) { |
| 92 |
|
$commitSha = getenv('CI_BUILD_REF'); |
| 93 |
|
if ($commitSha === false) { |
| 94 |
|
throw new \RuntimeException('Could not find the Gitlab build reference in the "CI_COMMIT_SHA" (Gitlab 9+) or "CI_BUILD_REF" (Gitlab 8.x) environment variable (usually set by Gitlab CI). Either set this environment variable or pass the build reference via the --commit-sha command line option.'); |
| 95 |
|
} |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
return $commitSha; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public function getJobStage() : string |
| 103 |
|
{ |
|
@@ 116-129 (lines=14) @@
|
| 113 |
|
return $commitSha; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
public function getGitlabBuildId() : int |
| 117 |
|
{ |
| 118 |
|
$buildId = $this->input->getOption('gitlab-job-id'); |
| 119 |
|
if ($buildId === null) { |
| 120 |
|
$buildId = getenv('CI_BUILD_ID'); |
| 121 |
|
if ($buildId === false) { |
| 122 |
|
$buildId = getenv('CI_JOB_ID'); |
| 123 |
|
if ($buildId === false) { |
| 124 |
|
throw new \RuntimeException('Could not find the Gitlab build id in the "CI_JOB_ID" (Gitlab 9+) or "CI_BUILD_ID" (Gitlab 8.x) environment variable (usually set by Gitlab CI). Either set this environment variable or pass the build id via the --gitlab-job-id command line option.'); |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
return $buildId; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
/** |
| 132 |
|
* Returns the current branch name (from Git) |