LoginSignup
2
5

More than 3 years have passed since last update.

GitLabでVS2019プロジェクトを自動ビルドするようにしてみた

Posted at

GitLab で VS2019プロジェクトを自動でビルドするようにしてみました。

環境

  • Windows 10 Home
  • GitLab CE 12.8.6
  • GitLab Runner 12.9.0
  • Git for Windows 2.25.1
  • Visual Studio Community 2019

フォルダ構成

ファイル/フォルダ 内容
TestProject_VS2019/ VS2019プロジェクトフォルダ
.gitignore Git無視リストファイル
.gitlab-ci.yml GitLab CI 設定ファイル
build.bat ビルド用バッチファイル
README.md 説明ファイル

ファイルの内容

.gitignore

不要なものもありますが、使いまわしています。

/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*

# Autogenerated VS/MD solution and project files
ExportedObj/
*.csproj
*.unityproj
# *.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd

# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Visual Studio
.vs
Release/
Debug/

.gitlab-ci.yml

GitLabにPUSHしたらビルドが走るようにしています。
同じPCにGitLab-Runnerをインストールして、Shared Runnerとして登録しています。

before_script:
  - chcp 65001
  - '"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat"'

stages:
  - build

job_build01:
  stage: build
  script:
    - echo "Start build"
    - ./build.bat
    - echo "Finish build"
  tags:
    - shared-runner
  artifacts:
    paths:
      - TestProject_VS2019/Release/TestProject_VS2019.exe
      - TestProject_VS2019/Debug/TestProject_VS2019.exe
    expire_in: 1 week

build.bat

ReleaseとDebugを順番にビルドしています。

SET MSBUILD="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"

%MSBUILD% TestProject_VS2019\TestProject_VS2019.sln -t:Rebuild -p:Configuration=Release -p:Platform="x86"
if %errorlevel% neq 0 (
  echo "build Release failed"
  goto :error_exit
)
%MSBUILD% TestProject_VS2019\TestProject_VS2019.sln -t:Rebuild -p:Configuration=Debug -p:Platform="x86"
if %errorlevel% neq 0 (
  echo "build Debug failed"
  goto :error_exit
)

goto :success_exit

:error_exit
echo "Error!!"
exit /b 1

:success_exit
echo "Finish!"
exit /b 0

実行結果

01.jpg

まとめ

GitLab で自動ビルドするようにしてみました。
同様にして、自動テストも入れたりすれば、効率よく作業ができるようになりそうです。

2
5
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
2
5