198

プロジェクトの GitHub Readme.md で Jenkins のビルド ステータスを表示する方法はありますか?

Jenkins を使用して継続的インテグレーション ビルドを実行しています。各コミットの後、最終的にドキュメントとリリース バンドルを生成する前に、すべてがコンパイルされ、単体テストと統合テストが実行されることが保証されます。

ビルドを壊す何かを誤ってコミットする危険性はまだあります。GitHub のプロジェクト ページにアクセスするユーザーは、現在のマスターがその状態であることを知っておくとよいでしょう。

4

14 に答える 14

175

OK、Jenkins をセットアップして GitHub のビルド ステータスを設定する方法は次のとおりです。これは、すべてのプッシュでビルドを実行するように構成された GitHub プラグインを備えた Jenkins が既にあることを前提としています。

  1. GitHub に移動してログインし、SettingsDeveloper SettingsPersonal access tokensに移動して、 Generate new tokenをクリックします。

    新しいトークンの生成のスクリーンショット

  2. repo:statusを確認します(これが必要かどうかはわかりませんが、私はそれを実行し、うまくいきました)。

    新しいトークンの生成のスクリーンショット

  3. トークンを生成し、コピーします。

  4. 使用する GitHub ユーザーが、リポジトリ コラボレーター (プライベート リポジトリの場合) であるか、ビルドするリポジトリへのプッシュおよびプル アクセス権 (組織リポジトリの場合) を持つチームのメンバーであることを確認してください。

  5. Jenkins サーバーに移動し、ログインします。

  6. Jenkins の管理システムの構成

  7. GitHub Web HookLet Jenkins auto-manage hook URLs を選択し、GitHubユーザー名と手順 3 で取得したOAuth トークンを指定します。

    Jenkins グローバル設定のスクリーンショット

  8. [ Test Credential ] ボタン で機能することを確認します。設定を保存します。

  9. Jenkins ジョブを見つけて、Set build status on GitHub commitをビルド後の手順に追加します。

    Jenkins ジョブ構成のスクリーンショット

それでおしまい。テスト ビルドを実行し、GitHub リポジトリに移動して、機能するかどうかを確認します。ビルド ステータスを表示するには、メイン リポジトリ ページの[ Branches]をクリックします。

「ブランチ」をクリックしたメインページのスクリーンショット

緑のチェックマークが表示されます。

ビルド ステータスを含む GitHub ブランチのスクリーンショット

于 2014-11-13T14:19:21.810 に答える
35

私がしたことは非常に簡単です:

  1. Hudson Post タスク プラグインをインストールする
  2. ここでパーソナル アクセス トークンを作成します: https://github.com/settings/tokens
  3. 常に成功する Post Task プラグインを追加する

    curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
      \"state\": \"success\",
      \"target_url\": \"${BUILD_URL}\",
      \"description\": \"The build has succeeded!\"
    }"
    
  4. 「ビルドが失敗としてマークされた」場合に失敗する投稿タスク プラグインを追加します。

    curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
      \"state\": \"failure\",
      \"target_url\": \"${BUILD_URL}\",
      \"description\": \"The build has failed!\"
    }"
    
  5. テストの開始時に保留中の呼び出しを追加することもできます

    curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
      \"state\": \"pending\",
      \"target_url\": \"${BUILD_URL}\",
      \"description\": \"The build is pending!\"
    }"
    

ビルド後のタスク構成のスクリーンショット

于 2014-01-07T17:07:47.527 に答える
27

このプラグインは動作するはずです: https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin

README.md次のようなバッジをファイルに埋め込むことができるはずです。

ビルド パッシング

于 2013-01-11T08:55:19.277 に答える
7

Githubにプラグインがインストールされている場合は、次のようJenkinsに実行できます。Post build actions

github でビルド ステータスを設定する

于 2014-06-17T16:39:12.300 に答える
2

アレックスの指示に従ったところ、うまくいきました。

ただし、GitHub Enterprise の場合、サーバーを Jenkins に追加するときに API URL を変更する必要があります。

たとえば、会社が creditcard.com の場合、URL は次のようになります。

https://github.creditcard.com/api/v3/

于 2019-01-24T18:14:20.317 に答える
1

Edit:

I'm no longer using this approach, please use one of the other answers.

Update: what I ended up doing, for our specific case: (above answers were great - thanks!)

Because our build server is not on the internet, we have a script to publish the build status to the gh-pages branch in github.

  • Start of build stamps failing
  • End of build stamps success
  • Project runs after main project to publish results -> build-status, API docs, test reports and test coverage.

GitHub caches images, so we created .htaccess file, that instructs a short cache timeout for the build-status image.

Put this in the directory with the build-status image:

ExpiresByType image/png "access plus 2 minutes"

Here's the build script. The target that publishes to gh-pages is '--publish.site.dry.run'

With less than 400 lines of config, we have:

  • Compile checks
  • unit & integration tests
  • Test Reports
  • Code Coverage Reports
  • API Docs
  • Publishing to Github

. . and this script can be run in or outside of Jenkins, so that:

  • Developers can run this script before commit, reducing the chance of a broken build that impacts others.
  • A failure is easy to reproduce locally.

The Results:

Project main page has the build status, updated after each build, along with latest API Docs, test results and test coverage.

于 2013-12-17T03:52:15.507 に答える
1

Github コミット ステータスをJently で更新します(上記の @vonc で説明されているように)。残念ながら、まだRepo Status APIを実装していません。

于 2014-04-07T07:10:59.823 に答える