.NET Core CI with Gitlab

April 2, 2019 Gitlab 0 minutes, 33 secondes

Avant de commencer, il faut s'assurer qu'un runner soit déclaré compatible pour ce type de compilation... sur ce point j'ai pu m'appuyer sur un architecte devops qui a configuré pour moi le runner.

image: microsoft/dotnet:latest

stages:
  - job_build_api
  - job_publish_api
  - job_dockerise_api

variables:
  project: "dotNetCoreApi"

job_build_api:
  stage: job_build_api
  variables:
    build_path: "$project/dotNetCoreApi"
  script:
    - "dotnet restore $project/dotNetCoreApi/dotNetCoreApi.csproj"
    - "cd $build_path"
    - "dotnet build dotNetCoreApi.csproj --configuration release"

job_publish_api :    
  stage: job_publish_api
  variables:
    prj_path: "$project/dotNetCoreApi"
  script:
    - "cd $prj_path"
    - "mkdir publish"
    - "dotnet publish dotNetCoreApi.csproj --configuration release --output /publish/"

job_dockerise_api :    
  image: docker:latest
  stage: job_dockerise_api
  services:
    - docker:dind  
  variables:
    prj_path: "$project/dotNetCoreApi"
  script:
    - "cd $prj_path"
    - docker build .
  dependencies:
    - job_build_api

alt