Bart\GitHook\StopTheLineJenkins::run PHP Method

run() public method

public run ( Commit $commit )
$commit Bart\Git\Commit
    public function run(Commit $commit)
    {
        if ($this->job->isHealthy()) {
            $this->logger->debug('Jenkins job is healthy.');
            return;
        }
        $this->logger->info('Jenkins job is not healthy...asserting that commit message contains {buildfix} hash');
        $messageSubject = $commit->messageSubject();
        $buildFixDirective = Directives::BUILD_FIX();
        // Check if commit has buildfix directive
        if (preg_match("/{$buildFixDirective->value()}/", $messageSubject) > 0) {
            $this->logger->info("Commit has {$buildFixDirective} directive. It attempts to fix build");
            return;
        }
        throw new GitHookException('Jenkins not healthy and commit does not fix it');
    }

Usage Example

Beispiel #1
0
 /**
  * @dataProvider dataProviderInvalidBuildFixDirectives
  * @param string $message Git commit message subject
  */
 public function testUnhealthyBuildAndInvalidBuildFixDirectives($message)
 {
     $this->mockJenkinsJobWithDependencies(false);
     $mockCommit = CommitTest::getStubCommit($this, 'HEAD', function ($head) use($message) {
         $head->messageSubject()->once()->return_value($message);
     });
     $stopTheLineJenkins = new StopTheLineJenkins();
     $this->setExpectedException('\\Bart\\GitHook\\GitHookException');
     $stopTheLineJenkins->run($mockCommit);
 }
StopTheLineJenkins