gitlab提交代码自动编译

gitlab提交代码后自动编译

公司的gitlab提交代码后会自动编译,然后可以直接下载编译后的执行程序。但是提交代码前需要添加ci文件(.gitlab-ci.yml)
这里以这次提交的RoleActionInfoTool程序为例,其ci文件为:

before_script:
  - chcp 65001
  - echo %CI_PROJECT_NAME%
  - echo FindMsbuild
  - for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
     set MSbuildInstallDir=%%i)
  - echo %MSbuildInstallDir%
  - set MSbuildDir=%MSbuildInstallDir%\MSBuild\15.0\Bin\
  - set PATH=%PATH%;%MSbuildDir%
  - echo %PATH%

#变量定义
variables: 
  TAG_VERSION:    "0.0.0.0"                  #本次编译tag版本号,如果没有tag,则默认为0.0.0.0
  SYMBOL_SERVER:  \\symbol.tac.com\symbol\x52  #pdb符号服务器
  RELEASE_DIR:        .\\exe\\RoleActionInfoTool\\

stages:
  - build
  - deploy

build vs2017:
  stage: build
  script:
    - nuget restore -FallbackSource http://nexus.tac.com/repository/nuget-hosted/ .\src\RoleActionInfoTool.sln
    - msbuild.exe src/RoleActionInfoTool.sln /p:Configuration=Release /t:build
    - rcedit.exe %RELEASE_DIR%RoleActionInfoTool.exe   --set-file-version %TAG_VERSION% --set-product-version %TAG_VERSION% --set-version-string ProductName %CI_COMMIT_SHA%
  artifacts:
    name: "%CI_PROJECT_NAME%-%CI_COMMIT_REF_NAME%-%CI_COMMIT_SHA%"
    expire_in: 2 week
    paths: 
        - "%RELEASE_DIR%"
  tags:
    - vs2017
  
deploy editor:
  stage: deploy
  only:
    - tags 
  script:
    - echo "deploy"
    - rcedit.exe %RELEASE_DIR%RoleActionInfoTool.exe --set-file-version %CI_COMMIT_REF_NAME% --set-product-version %CI_COMMIT_REF_NAME% --set-version-string ProductName %CI_COMMIT_SHA%
    - symstore.exe add /r /f "%RELEASE_DIR%*.*" /s %SYMBOL_SERVER% /t "%CI_PROJECT_NAME%" /v "Release"
    - del *.pdb /s  
  dependencies:
    - build vs2017
  artifacts:
    name: "%CI_PROJECT_NAME%-%CI_COMMIT_REF_NAME%-%CI_COMMIT_SHA%"
    expire_in: 50 week
    paths: 
        - "%RELEASE_DIR%"
  tags:
    - vs2017

Release下其输出路径如图所示

这里其目录结构:

posted @ 2019-11-25 20:31  黑色的夢  阅读(1118)  评论(0)    收藏  举报