Reputation: 7681
I have a toy C++ cmake project with the following azure-pipelines.yml (see HelloAzure for sources).
# 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
Locally I can do the following:
# 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
I am trying to reproduce this workflow in azure. It is trivial to do using just one stage, but as soon as I try to run the tests in a "test" stage, Azure simply re-downloads the sources and tried to run the tests without first having ran the build command.
So my question, what is the proper mechanism for separating the build and test stages of a project in azure-pipelines?
Upvotes: 0
Views: 534
Reputation: 31033
For your scenario, you may try the following approach:
1 .In Build stage, adding a task to publish the build output. For example:
steps:
- publish: string # path to a file or folder
artifact: string # artifact name
displayName: string # friendly name to display in the UI
2 .In BuildTests stage, adding a task to download the build output:
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 .Nondeployment jobs automatically check out source code. Use the checkout
keyword to configure or suppress this behavior. In BuildTests stage, adding the following step to suppress automatically the source code checked out:
steps:
- checkout: none
Upvotes: 1