オンプレミスのプロキシ環境下にある GitLab で、.NET Core で作成したアプリケーションの自動ビルドと自動テストを GitLab CI を使って行ってみました。
環境
- Visual Studio 2017
- .NET Core 2.0
- xUnit.NET
- GitLab CE 10.1.2
準備
GitLab CI を使用するには別途タスクランナーとして gitlab-runner
が必要です。gitlab-runner
の準備と設定は以下の過去記事を参考にしてください。
- http://kuttsun.blogspot.jp/2017/09/gitlab-runner-docker-compose.html
- http://kuttsun.blogspot.jp/2017/10/gitlab-runner-gitlab.html
.gitlab-ci.yml の作成
とりあえず作成した .gitlab-ci.yml
は以下です。
# .gitlab-ci.yml
image: microsoft/dotnet:2.0.0-sdk
stages:
- build
- test
job1:
stage: build
script:
- export http_proxy=http://xxx.xxx.xxx.xxx:8080
- export https_proxy=http://xxx.xxx.xxx.xxx:8080
- dotnet restore
- dotnet build
tags:
- docker
job2:
stage: test
script:
- export http_proxy=http://xxx.xxx.xxx.xxx:8080
- export https_proxy=http://xxx.xxx.xxx.xxx:8080
- dotnet restore
- dotnet test テストプロジェクト名
tags:
- docker
常に最新の SDK を使用したい場合、image は microsoft/dotnet:sdk
で OK です。
また、dotnet restore
で NuGet パッケージの復元が行われるので、プロキシ環境下で動作させている場合は、プロキシの設定が必要です(地味にはまったところ・・・)。
なので、 export http_proxy
export https_proxy
でプロキシサーバーを指定しています。
参考 URL
- http://docs.gitlab.com/ce/ci/yaml/README.html
- https://qiita.com/tsgkdt/items/ef1cfee3cf6b58b87900
- https://docs.microsoft.com/en-us/dotnet/core/docker/building-net-docker-images
- http://blog.makotoishida.com/2017/09/gitlab-ciwebapipdf.html
- http://tech.tanaka733.net/entry/http_proxy-in-dotnetcore-on-linux