在azure管道中,分离构建和测试阶段的适当机制是什么



我有一个玩具C++cmake项目,包含以下azure-pipelines.yml(有关源代码,请参阅HelloAzure(。

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master 
variables:
SOURCE_DIR: '$(System.DefaultWorkingDirectory)'
BUILD_DIR: '$(SOURCE_DIR)/build'
INSTALL_DIR: '$(SOURCE_DIR)/install'
stages:
- stage: Build 
displayName: Build 
pool: 
vmImage: ubuntu-latest    
jobs:
- job: BuildLinux 
strategy:
matrix:
Release:
BUILD_TYPE: 'Release'
Debug:
BUILD_TYPE: 'Debug'
steps:
- script: | 
echo "mkdir BUILD_DIR $(BUILD_DIR)"
mkdir $(BUILD_DIR)
echo "cd build directory "
cd $(BUILD_DIR)
echo " Run configure command"
cmake -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR)/$(BUILD_TYPE) $(SOURCE_DIR)
echo "running cmake build command"
cmake --build . --target install --config $(BUILD_TYPE) -j 12 
- stage: BuildTests
dependsOn: Build
displayName: BuildTests 
jobs: 
- job: RunCTestLinux 
steps: 
- script: |
cd $(BUILD_DIR)
ctest

在本地我可以做以下事情:

# download sources
git clone https://github.com/CiaranWelsh/HelloAzure.git
# build
cd HelloAzure
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=../install ..
cmake --build . --target install --config Release -j 12
# test
ctest

我正在尝试在azure中复制此工作流。只使用一个阶段是微不足道的,但只要我尝试在";测试";阶段,Azure只需重新下载源代码,并尝试在没有首先运行build命令的情况下运行测试。

那么,我的问题是,在azure管道中,将项目的构建和测试阶段分开的合适机制是什么?

对于您的场景,您可以尝试以下方法:

1.在Build阶段,添加一个任务以发布生成输出。例如:

steps:
- publish: string # path to a file or folder
artifact: string # artifact name
displayName: string  # friendly name to display in the UI

2.在BuildTests阶段,添加一个任务来下载构建输出:

steps:
- download: [ current | pipeline resource identifier | none ] # disable automatic download if "none"
artifact: string ## artifact name, optional; downloads all the available artifacts if not specified
patterns: string # patterns representing files to include; optional
displayName: string  # friendly name to display in the UI

3.非部署作业会自动签出源代码。使用checkout关键字可以配置或抑制此行为。在BuildTests阶段,添加以下步骤以自动抑制签出的源代码:

steps:
- checkout: none

最新更新