我正在学习gitlab-runner的工作方式,并创建一个脚本来运行Windows C#项目的构建。
我在外壳上安装了一个运行器,并安装了所有必需的工具来进行构建,但是现在我需要创建一个好的.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。有办法解决这个问题吗?
如果还有其他要注意的地方,我总是要记住...(就像我说我还在学习)
答案 0 :(得分:0)
我发现答案显然是您可以有多个依赖关系,这是一个or语句。
例如:
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