LoginSignup
3
0

More than 5 years have passed since last update.

Jenkins と Gitlab の連携

Last updated at Posted at 2018-12-19

プラグインがインストールされている状態での設定方法。設定方法がよく変わるらしく悩んだので記録する。

Gitlab から Jenkins にビルド開始を伝える Jenkins CI service

Jenkins から Gitlab にビルド完了を伝える

Gitlab の Jenkins CI service のドキュメントには、あたかも Gitlab 側で設定するだけで Gitlab pipeline との連携が出来る かのように書いてあるが嘘だった。Gitlab pipeline と連携するには以下のように Jenkins ファイルの適当な位置に適当なコマンドを入れる必要がある。ざっくり書くとこんな感じだった。

pipeline {
  agent any

  options {
    gitLabConnection('Your GitLab Connection')
  }

  stages {
    stage('build') {
      steps {
        updateGitlabCommitStatus name: 'build', state: 'running'
        hogehoge
      }
    }
  }

  post {
    success {
      updateGitlabCommitStatus name: 'build', state: 'success'
    }
    failure {
      updateGitlabCommitStatus name: 'build', state: 'failed'
    }
  }
}
  • gitLabConnection とは、GitLab との接続を表す名前。権限によっては一般ユーザには見えないが、ビルドしたブランチに行って View Configuration > General > GitLab Connection で見ることが出来る。
  • updateGitlabCommitStatus
    • name: build など適当な名前
    • state: pending, running, canceled, success, failed のどれか

参考

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0