首页 > 解决方案 > Gitlab CI 对发布或调试构建的依赖

问题描述

我正在学习 gitlab-runner 如何工作,并创建一个脚本来运行 Windows C# 项目的构建。

我在我的 shell 上设置了一个运行器并安装了所有需要的工具来构建,但现在我需要创建一个好的 .yml 脚本来运行。

我已经有一些代码,但我不知道是否可以有多个依赖项,比如 OR

这是我想要设置的方式: 步骤

这就是我现在所拥有的:

variables:
  PROJECT_LOCATION: "ProjectFolder"
  PROJECT_NAME: "ProjectName"

before_script:
  - echo "starting build for %PROJECT_NAME%"
  - cd %PROJECT_LOCATION%

stages:
  - build
  - artifacts
  - test
  - deploy

build:debug:
  stage: build
  script:
  - echo "Restoring NuGet Packages..."
  - 'nuget restore "%PROJECT_NAME%.sln"'
  - echo "Starting debug build..."
  - 'msbuild /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Debug /verbosity:quiet /p:AllowUnsafeBlocks=true /nr:false "%PROJECT_NAME%.sln"'
  except:
    - master
  tags:
    - windows

build:release:
  stage: build
  script:
  - echo "Restoring NuGet Packages..."
  - 'nuget restore "%PROJECT_NAME%.sln"'
  - echo "Starting release build..."
  - 'msbuild /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet /p:AllowUnsafeBlocks=true /nr:false "%PROJECT_NAME%.sln"'
  only:
    - master
  tags:
    - windows

artifacts:
  stage: artifacts
  script:
  - echo "Creating artifacts..."
  dependencies: 
    - build
  artifacts:
    name: "Console"
    paths:
      - Project.Console/bin/
    expire_in: 2 days
    untracked: true

    name: "Service"
    paths:
       - Project.Service/bin/
    expire_in: 1 week
    untracked: true
  only:
    - tags
    - master
    - schedules
  tags:
    - windows

test:unit:
  stage: test
  script:
  - echo "Running tests..."
  dependencies: 
    - build
  tags:
    - windows

test:integration:
  stage: test
  script:
  - echo "Running integration tests..."
  dependencies: 
    - build
  only:
    - tags
    - master
    - schedules
  tags:
    - windows

deploy:
  stage: deploy
  script:
  - echo "Deploy to production..."
  dependencies: 
    - build
  environment:
    name: production
  only:
    - tags
  tags:
    - windows

但是正如你所看到的,我给了它依赖构建,它不喜欢这样,因为我有 build:debug 和 build:release。有没有办法解决这个问题?

如果还有其他指示我需要牢记始终欢迎......(就像我说的我还在学习)

标签: gitlabgitlab-cigitlab-ci-runner

解决方案


I found the answer apparently you can have multiple dependencies and this is an or statement.

So for example:

artifacts:
  stage: artifacts
  script:
  - echo "Creating artifacts..."
  dependencies: 
    - build:debug
    - build:release
  artifacts:
    name: "Console"
    paths:
      - Project.Console/bin/
    expire_in: 2 days
    untracked: true

    name: "Service"
    paths:
       - Project.Service/bin/
    expire_in: 1 week
    untracked: true
  only:
    - tags
    - master
    - schedules
  tags:
    - windows

推荐阅读