テンプレートテスト
ブログの説明
ブログの説明2
menu
keyboard_arrow_up
Top
search
close
home
ホーム
computer
PC一般
construction
開発環境・ツール
code
プログラミング
home
ホーム
computer
PC一般
construction
開発環境・ツール
code
プログラミング
ラベル
SonarQube
の投稿を表示しています。
すべての投稿を表示
ラベル
SonarQube
の投稿を表示しています。
すべての投稿を表示
2018/04/29
image
NO IMAGE
SonarQube で LDAP 認証を行う
update
event_note
label
SonarQube
SonarQube で LDAP 認証 (Active Directory) を行う方法です。
## プラグインのインストール まずは LDAP Plugin をインストールします。 プロキシ設定を適切に行っていれば [Administration] > [Marketplace] からインストールできます。 `LADP` で検索してインストールを行います。 ## 設定 SonarQube の設定は以下に記述します。 `/opt/sonarqube/conf/sonar.properties` プラグインをインストールしたら、sonar.properties に設定を追記します。 以下は例です。 ``` # LDAP sonar.security.realm=LDAP ldap.url=ldap://example.com:389 ldap.bindDn=user@example.com ldap.bindPassword=password ldap.user.baseDn=dc=example,dc=com ldap.user.request=(&(objectClass=user)(sAMAccountName={login})) ldap.user.realNameAttribute=cn ldap.user.emailAttribute=mail ``` 注意事項として、LADP プラグインのインストール前に上記の設定を行うと、起動エラーになります。 私はこれで結構はまりました・・・。
Read more
2018/04/28
image
NO IMAGE
SonarQube のプロキシ設定
update
event_note
label
SonarQube
SonarQube でプロキシサーバーの設定を行う方法です。
プロキシ環境下ではプロキシ設定を行っておかないとプラグインのインストールなどができません。 ## 設定方法 SonarQube の設定は以下に記述します。 `/opt/sonarqube/conf/sonar.properties` `sonar.properties` をテキストエディタで開き、以下の行のコメントアウトを解除して設定します。 ``` # HTTP proxy (default none) http.proxyHost=example.com http.proxyPort=8080 # HTTPS proxy (defaults are values of http.proxyHost and http.proxyPort) https.proxyHost=example.com https.proxyPort=8080 ``` SonarQube を再起動します。
Read more
2017/12/28
[C#] GitLab CI と SonarQube で .NET アプリケーションの CI を行う
update
event_note
label
.NET Core
label
C#
label
GitLab
label
SonarQube
以前の記事で SonarQube を使って .NET アプリケーションの静的解析を行いました。 今回はこれに GitLab CI を使って継続的インテグレーションを行います。
具体的には Push をトリガーとして自動的にコードを解析を行い、またその解析結果をマージリクエストの画面に表示します。 尚、Jenkins 等の他の CI ツールは必要ありません。 ## 環境 - GitLab 10.2.0 - gitlab-runner 10.2.0 - SonarQube 6.7 - SonarQube Scanner for MSBuild 4.0 - .NET Core 2.0 ## 準備 GitLab と SonarQube の環境構築は済んでいる前提です。 Docker を使った環境構築については以下を参考にしてください。 - [GitLab を docker-compose で動かしてみる](http://kuttsun.blogspot.jp/2016/09/dockergitlab.html) - [SonarQube を docker-compose で動かしてみる](http://kuttsun.blogspot.jp/2017/12/sonarqube-docker-compose.html) また、GitLab CI を使うためにはタスクランナーとして gitlab-runner が必要です。 以下の記事に書いたように、C# プログラムのコード解析には OpenCover と SonarQube Scanner を使っていますが、これらは Windows 上でしか動作しません。 - [[C#] OpenCover でコードカバレッジを計測する](http://kuttsun.blogspot.jp/2017/12/opencover.html) - [[C#] SonarQube で .NET アプリケーションのコード解析を行う](http://kuttsun.blogspot.jp/2017/12/sonarqube-net.html) 従って、gitlab-runner は Windows 上にインストールしたものを使う必要があります。 gitlab-runner を Windows にインストールする手順については以下の記事を参照してください。 - [GitLab Runner を Windows で動かす](http://kuttsun.blogspot.jp/2017/12/gitlab-runner-windows.html) GitLab に gitlab-runner を登録するところまでも済んでいる前提とします。 ## GitLab の設定 ### ユーザーの追加 SonarQube から GitLab に通知するためのユーザーを GitLab に作成します。 後で SonarQube の設定を行うときに作成したユーザーのトークンが必要になります。 トークンは作成したユーザーでログインし、Account のメニューの Private Token で確認できます。 もちろん、別途トークンを作成しても OK です。 ### Pipeline 失敗時のマージ拒否 Pipeline で失敗している場合にマージリクエストをマージできないようにしたい場合は、該当のプロジェクトで以下を設定します。 [Edit Project] > `Only allow merge requests to be merged if the build succeeds` を ON にし、`Save changes` をクリック ## SonarQube の設定 管理者アカウントでログインして以下のことを行います。 ### GitLab Plugin のインストール [Administration] > [Marketplace] > `GitLab` で検索し、`GitLab` をインストールします。
インストールしたら SonarQube を再起動します。 ### GitLab Plugin の設定 [Administration] > [Configuration] > サイドメニューより `GitLab` を選択します。 `GitLab url` と `GitLab User Token` を設定します。 `GitLab User Token` には、あらかじめ GitLab に作成しておいたアカウントのトークンを設定します。
詳細は以下を参照してください。 - https://gitlab.talanlabs.com/gabriel-allaigre/sonar-gitlab-plugin ### プロジェクトの設定 該当のプロジェクトの画面で以下を設定します。 [Administration] > [General Settings] > サイドメニューより `GitLab` を選択します。 `GitLab Project id` を設定します。
## .gitlab-ci.yml の作成 GitLab と SonarQube の設定が完了したら、.gitlab-ci.yml を作成します。 SonarQube のコード解析の部分だけのサンプルですが、例えば以下のような感じです。 ```xml variables: SONARSCANNER: "C:\\SonarQube\\sonar-scanner-msbuild-4.0.0.821\\MSBuild.SonarQube.Runner.exe" SONARHOST: "http://localhost:9000" SONARKEY: "projectkey" REPORT: "coverage.xml" stages: - test Job1: stage: test script: # GitLab のコンソールログでの文字化け対策 - chcp 65001 # SonarQube による解析(環境変数を先頭に置くと yaml パーサーでエラーになるので call をつけている) - call %SONARSCANNER% begin /d:sonar.host.url=%SONARHOST% /k:%SONARKEY% /v:"1.0" /d:sonar.analysis.mode=preview /d:sonar.cs.opencover.reportsPaths=%REPORT% /d:sonar.gitlab.commit_sha=%CI_COMMIT_SHA% /d:sonar.gitlab.project_id=%CI_PROJECT_ID% /d:sonar.gitlab.ref_name=%CI_COMMIT_REF_NAME% - dotnet build - call .\OpenCover.bat %REPORT% - call %SONARSCANNER% end tags: - windows ``` OpenCover の解析部分はバッチファイルにしていますが、中身については以下の記事を参考にしてください。 - [[C#] OpenCover でコードカバレッジを計測する](http://kuttsun.blogspot.jp/2017/12/opencover.html) SonarQube の解析も、後述するように SonarQube Server と GitLab の通知のために2回行うことを前提にするならば、バッチファイルにして処理を共通化したほうが良いかなと思います。 まぁそれはともかく、とりあえずこれで全て完了です。 これで以下のように動作します。 - GitLab に Push したタイミングで GitLab CI の機能により、最新コミットのコード解析が行われる - SonarQube での解析結果が GitLab に通知される - 解析を行ったコミットが含まれるマージリクエストに指摘事項が表示される マージリクエストの画面にはこんな感じで表示されます。
SonarQube Scanner for MSBuild のパラメータの一覧は以下を参照してください。 - https://gitlab.talanlabs.com/gabriel-allaigre/sonar-gitlab-plugin .gitlab-ci.yml で使用できる環境変数の一覧は以下を参照してください。 - https://docs.gitlab.com/ee/ci/variables/README.html 今回使用しているパラメータについては以下に簡単に説明します。 **sonar.analysis.mode** デフォルトは `publish` で、この場合、解析結果が SonarQube Server にアップロードされます。 GitLab に通知したい場合は、`preview` を指定する必要があります。 SonarQube Server と GitLab の両方に通知したい場合は、面倒ですが `sonar.analysis.mode` の値を変えて2回解析を実行する必要があります。 尚、`publish` の場合に後述の GitLab 関連のオプションを設定していると解析に失敗するので注意です。 **sonar.host.url** SonarQube Server の URL を指定します。 **sonar.cs.opencover.reportsPaths** OpenCover の出力ファイルを指定します。 **sonar.gitlab.commit_sha** 解析対象の Git のコミットのハッシュ値を指定します。 **sonar.gitlab.project_id** GitLab のプロジェクト ID を指定します。 SonarQube のプロジェクト設定で設定済みの場合は不要っぽいです。 **sonar.gitlab.ref_name** ブランチ名を指定します。 **sonar.gitlab.user_token** GitLab に通知する際のユーザーのトークンを指定します。 SonarQube で設定済みの場合は不要っぽいです。 ## はまったところ 何度見直しても正しく設定しているはずなのに、解析結果が GitLab に通知されずずっと悩んでいました。 解析ログをよく見ると、以下の警告が表示されていました。 ``` The project does not have a valid "ProjectGuid." ``` `ProjectGuid` が何なのかわからないまま調べてみると、どうやら .NET Core の ProjectGuid 変更になったらしく、これを手動で追加すると解析結果が GitLab に通知されるようになりました。 詳細は以下の記事を参照してください。 - http://kuttsun.blogspot.jp/2017/12/net-core-projectguid.html ## 参考 URL - http://codeout.hatenablog.com/entry/2015/08/21/012706 - https://qiita.com/bremen/items/f47f383b9931a840a25c - https://gitlab.talanlabs.com/gabriel-allaigre/sonar-gitlab-plugin - https://qiita.com/ynott/items/1ff698868ef85e50f5a1 - https://eliot-jones.com/2017/12/configure-gitlab-sonarqube-teamcity - https://docs.gitlab.com/ce/ci/variables/README.html#using-the-ci-variables-in-your-job-scripts - http://blog.applibot.co.jp/blog/2017/09/14/static-code-analysis-with-sonarqube/ - https://github.com/gabrie-allaigre/sonar-gitlab-plugin/issues/75 - https://github.com/mibexsoftware/sonar-bitbucket-plugin/issues/25 - https://qiita.com/teradonburi/items/776e4735395af872320a - https://qiita.com/ijoji/items/f7dce812c84a5cfa91cf
Read more
2017/12/20
image
NO IMAGE
[C#] SonarQube で .NET アプリケーションのコード解析を行う
update
event_note
label
.NET Core
label
C#
label
SonarQube
SonarQube を使って .NET アプリケーションを静的解析します。
## 概要 コードカバレッジの計測自体は OpenCover を使って行い、その出力結果を SonarQube にインポートします。 詳細は以下のページで解説されています。 - [SonarC#](https://docs.sonarqube.org/pages/viewpage.action?pageId=1441900) ## 環境 - Visual Studio 2017 - .NET Core 2.0 - SonarQube 6.7 - SonarQube Scanner for MSBuild 4.0 今回は .NET Core を使って試しましたが、Windows 環境なので .NET Framework であっても同じようにできるはずです。 ## SonarQube Server の準備 SonarQube Server をあらかじめ用意しておく必要があります。 Docker を使った構築については以下を参照してください。 - [SonarQube を docker-compose で動かしてみる](http://kuttsun.blogspot.jp/2017/12/sonarqube-docker-compose.html) その後、プロジェクトを作成して、 API キーを発行しておいてください。 ## SonarQube Scanner for MSBuild のダウンロード OpenCover の解析結果を SonarQube にインポートするには SonarQube Scanner が必要です。 - https://docs.sonarqube.org/display/SCAN ここでは SonarQube Scanner for MSBuild を使用します。 ## 実行 以下のようなバッチファイルを作成して実行しました。 ```sh rem SonarQube Scanner fo MSBuild のインストール先 set SONARQUBE=C:\SonarQube\MSBuild.SonarQube.Runner.exe %SONARQUBE% begin /d:sonar.host.url=http://localhost:9000 /k:"hogehoge" /n:"MyApplication" /v:"1.0" /d:sonar.cs.opencover.reportsPaths="coverage.xml" dotnet build call OpenCover.bat %SONARQUBE% end ``` `MSBuild.SonarQube.Runner.exe begin` で解析を開始します。 ここでいくつかパラメータを指定する必要があります。 - `/d:sonar.host.url=` で SonarQube Server の URL を指定 - `/k:` でプロダクトキーを指定 - `/n:` でプロジェクト名を指定 - `/v:` でバージョンを指定 - `/d:sonar.cs.opencover.reportsPaths=` で解析結果のレポートを指定(これは後述するように OpenCover の出力結果を与えます) 解析を開始したら、まずビルドを行います。 今回は .NET Core なので、`dotnet build` を指定します。 次にカバレッジの計測を行います。 今回は OpenCover を使って計測するので、そこを別途バッチファイルに記述しています。 このバッチファイルの中身については以下の記事を参考にしてください。 - [OpenCover でコードカバレッジを計測する](http://kuttsun.blogspot.jp/2017/12/opencover.html) ビルドとカバレッジ計測が終わったら、`MSBuild.SonarQube.Runner.exe end` で解析を終了します。 正常に解析が完了していれば、SonarQube で結果を確認することができます。 尚、今回は OpenCover しか使っていませんが、他のいろいろツールを併用することもできます。 - https://docs.sonarqube.org/pages/viewpage.action?pageId=6389770#CodeCoverageResultsImport(C#,VB.NET)-OpenCover ## 継続的インテグレーション とりあえず解析自体は出来ましたが、こういうのはやはり自動化して継続的に行いたいものです。 これについてはまた別途書きます。 ## 参考 URL - https://docs.sonarqube.org/pages/viewpage.action?pageId=1441900 - http://d.hatena.ne.jp/pneumaster/20151230/1451480090 - http://posaune.hatenablog.com/entry/2013/12/04/083834 - https://blog.nijohando.jp/post/gitlab-merge-request-sonarqube/ - https://budougumi0617.github.io/post/2017/07/13/opencover-to-vs2017/
Read more
2017/12/06
image
NO IMAGE
SonarQube を docker-compose で動かしてみる
update
event_note
label
Docker
label
SonarQube
C# で作成したアプリケーションの静的解析を行うために、SonarQube をインストールしてみました。
尚、いつもの通り Docker を使ってインストールします。 (Docker に慣れてくると全て Docker で構築したくなってきます。) ## 環境 - Docker for Windows ## docker-compose.yml 作成した `docker-compose.yml` は以下のような感じです。 SonarQube は公式のイメージがあるのでそれを使用します。 ```sh version: '2' services: sonarqube: image: sonarqube container_name: sonarqube restart: always ports: - 9000:9000 environment: - SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_db:5432/sonar volumes: - conf:/opt/sonarqube/conf - data:/opt/sonarqube/data - extensions:/opt/sonarqube/extensions - bundled-plugins:/opt/sonarqube/lib/bundled-plugins sonarqube_db: image: postgres container_name: sonarqube_db restart: always environment: - POSTGRES_USER=sonar - POSTGRES_PASSWORD=sonar volumes: - postgresql:/var/lib/postgresql # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52 - postgresql_data:/var/lib/postgresql/data volumes: conf: data: extensions: bundled-plugins: postgresql: postgresql_data: ``` ## 管理者でログイン 起動したら以下の管理者 ID でログインできます。 - Username : admin - Password : admin ## SonarQube の設定 SonarQube の設定は `/opt/sonarqube/conf/sonar.properties` に記述します。 ### プロキシの設定 プロキシ環境下ではプロキシ設定を行っておかないとプラグインのインストールなどができません。 - https://docs.sonarqube.org/display/SONAR/Marketplace `sonar.properties` の以下の行のコメントアウトを解除して設定します。 ```sh # HTTP proxy (default none) http.proxyHost=xxx.xxx.xxx.xxx http.proxyPort=8080 # HTTPS proxy (defaults are values of http.proxyHost and http.proxyPort) https.proxyHost=xxx.xxx.xxx.xxx https.proxyPort=8080 ``` ### LDAP 認証の設定 社内の Active Directory で LDAP 認証を行うための設定を行います。 まずは LDAP Plugin をインストールします。 プロキシ設定を適切に行っていれば [Administration] > [Marketplace] からインストールできます。 - https://docs.sonarqube.org/display/PLUG/LDAP+Plugin `sonar.properties` に以下を追記します。 内容は環境に応じて適宜変更します。 ```sh # LDAP sonar.security.realm=LDAP ldap.url=ldap://example.com:389 ldap.bindDn=hoge@example.com ldap.bindPassword=xxxxxxxx ldap.user.baseDn=dc=example,dc=com ldap.user.request=(&(objectClass=user)(sAMAccountName={login})) ldap.user.realNameAttribute=cn ldap.user.emailAttribute=mail ``` ### SMTP の設定 管理者アカウントでログインします。 [Administration] > [Configuration] > [General] の [Email] で設定します。 ## 参考 URL - https://qiita.com/ot-aoyagi/items/d97b2431fefbf5635e93 - https://qiita.com/teradonburi/items/776e4735395af872320a - https://qiita.com/yo1000/items/0af36c8bc5e944c1e42a - https://github.com/SonarSource/docker-sonarqube/blob/master/recipes.md - https://qiita.com/okamu_/items/1c8e5fde742ca165fa12#sonarqube - http://blog.applibot.co.jp/blog/2017/09/14/static-code-analysis-with-sonarqube/
Read more
前の投稿
ホーム
Translate
Popular Posts
ASP.NET Core で AdminLTE を使用する
TortoiseGit でコミットメッセージを変更する
TortoiseGit でリモートリポジトリのタグを削除する
image
NO IMAGE
ASP.NET Core におけるフロントエンドのパッケージ管理
image
NO IMAGE
C# と C/C++ のライブラリを混在させる場合の構成
image
NO IMAGE
[C#] Dictionary の キーがタプルの場合に JSON へのシリアライズとデシリアライズを行う方法
image
NO IMAGE
TortoiseGit でブランチ間の差分を見る
image
NO IMAGE
ASP.NET Core (.NET Core) でバックグランドタスクを起動する
image
NO IMAGE
.NET アプリケーションを XCOPY 配置で配布する
image
NO IMAGE
TestLink で LDAP 認証を行う
Labels
.NET Core
31
.NET Framework
17
.NET Standard
2
AdminLTE
1
Apache
3
AppVeyor
2
AsciiDoc
3
ASP.NET Core
55
Atom
4
AWS
2
AWS Cloud9
4
blockdiag
1
Blogger
10
Bootstrap
3
C/C++
6
C#
106
CentOS
3
Chrome
1
Chronograf
3
Codecov
1
CSS
1
Docker
28
DokuWiki
4
Doxygen
1
draw.io
1
Electron.NET
2
Entity Framework Core
9
Excel
2
FFmpeg
2
Firefox
5
Git
12
GitBook
4
GitBucket
7
GitHub
7
GitLab
30
Go
1
Google
1
Google Cloud Platform
1
Grafana
5
HTML
5
IIS
8
InfluxDB
6
JavaScript
7
Jenkins
7
Linux
25
Log4View
1
MahApps.Metro
3
MaterialDesignInXamlToolkit
1
MVC
1
MVVM
6
NLog
3
Node.js
3
npm
1
OpenSSL
3
ownCloud
2
Pine Script
1
PlantUML
5
PowerShell
7
Prism
2
Python
11
Razor
3
Redmine
30
remark.js
2
rocketchat
4
Ruby
3
SignalR
1
Socket.IO
1
SonarQube
5
Sphinx
10
SQL Server
5
SQLite
1
t
1
TestLink
2
Tomcat
2
TortoiseGit
10
TortoiseSVN
2
Trading View
1
Travis CI
1
Ubuntu
13
Visual Studio
39
Visual Studio Code
9
Vue.js
8
Windows
56
Windows 10
4
Windows ADK
1
Windows API
2
Windows Embedded
4
wkhtmltopdf
2
Word
3
WPF
12
WSL
1
Xamarin
1
xUnit
5
アプリケーション
1
デザインパターン
1
テスト
3
バッチファイル
2
ぴよ
3
プログラミング
3
ライセンス
1
ラベル
3
ラベル1
2
英語
2
雑記
1
書籍
1
数学
1
正規表現
1
Blog Archive
▼
2022
(1)
▼
2月
(1)
例えばボタンをクリックしたときに重い処理を実行する場合など、そのまま処理すると GUI が固まって...
►
2021
(24)
►
5月
(7)
►
4月
(8)
►
3月
(2)
►
2月
(2)
►
1月
(5)
►
2020
(60)
►
12月
(1)
►
11月
(3)
►
10月
(3)
►
9月
(3)
►
8月
(3)
►
7月
(7)
►
6月
(7)
►
5月
(2)
►
4月
(6)
►
3月
(6)
►
2月
(7)
►
1月
(12)
►
2019
(92)
►
12月
(13)
►
11月
(9)
►
10月
(3)
►
9月
(2)
►
8月
(3)
►
7月
(5)
►
6月
(11)
►
5月
(6)
►
4月
(17)
►
3月
(9)
►
2月
(6)
►
1月
(8)
►
2018
(100)
►
12月
(1)
►
11月
(11)
►
10月
(8)
►
9月
(6)
►
8月
(10)
►
7月
(10)
►
6月
(8)
►
5月
(9)
►
4月
(8)
►
3月
(14)
►
2月
(4)
►
1月
(11)
►
2017
(117)
►
12月
(14)
►
11月
(20)
►
10月
(17)
►
9月
(19)
►
8月
(10)
►
7月
(8)
►
6月
(3)
►
5月
(6)
►
4月
(5)
►
3月
(2)
►
2月
(8)
►
1月
(5)
►
2016
(91)
►
12月
(5)
►
11月
(9)
►
10月
(11)
►
9月
(9)
►
8月
(6)
►
7月
(14)
►
6月
(14)
►
5月
(11)
►
4月
(10)
►
3月
(2)
►
2015
(23)
►
12月
(4)
►
11月
(2)
►
10月
(8)
►
9月
(8)
►
7月
(1)
►
2013
(3)
►
11月
(1)
►
9月
(1)
►
7月
(1)
►
2012
(2)
►
7月
(1)
►
6月
(1)
►
2011
(1)
►
9月
(1)
►
2009
(1)
►
7月
(1)
►
2008
(2)
►
11月
(1)
►
7月
(1)
►
2007
(3)
►
10月
(3)