Boh*_*huk 7 java azure-devops azure-pipelines
我正在尝试使用 Azure 管道为一个存储库中包含的多个 Java 项目构建 CI/CD。
为此,需要创建一个管道,该管道将使用 Maven@3 任务构建每个项目。问题是,当我们添加新项目时,我希望只构建这个项目,而不是之前的每个项目。我的文件看起来像:
resources:
- repo: self
clean: true
lfs: true
trigger:
branches:
include:
- feature/*
variables:
- group: vars
stages:
- stage: Build
pool:
vmImage: 'image'
jobs:
- job: Build
strategy:
maxParallel: 4
steps:
- task: replacetokens@3
inputs:
targetFiles: 'settings.xml'
- task: Maven@3
inputs:
jdkVersionOption: 1.8
mavenPomFile: 'project1/pom.xml'
options: '-s $(Build.SourcesDirectory)\settings.xml'
goals: 'clean package'
- task: Maven@3
inputs:
jdkVersionOption: 1.8
mavenPomFile: 'project2/pom.xml'
options: '-s $(Build.SourcesDirectory)\settings.xml'
goals: 'clean package'
Run Code Online (Sandbox Code Playgroud)
例如project1在develop中已经alraedy了,所以我不想为它做mvn包,而只是为project2做mvn包,它没有合并并且有功能分支。
现在这个 yml 不起作用,因为 project1 和 project2 在同一个 repo 中,这两个任务将运行,这是我不想避免的。
有没有办法说“onChange”???
Unfortunately, this is not possible out of the box which is a shame, to be honest.
The easiest way to handle this would be to create two separate builds. One build for each project you want to build that is located in the same repo and use the path filter like this:
trigger:
branches:
include:
- master
- releases/*
paths:
include:
- docs/*
exclude:
- docs/README.md
Run Code Online (Sandbox Code Playgroud)
Use step templates and define a single build task or job that you can then use across multiple builds so it is easier to maintain if multiple projects have the same build steps.
Link to the documentation: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#step-templates
然而,互联网上有一些指南,人们在其中编写了一些 Powershell 脚本来实现 mono repo 单一构建解决方案。
一个例子是这样的:
https://dev.to/nikolicbojan/azure-devops-yaml-build-for-mono-repository-with-multiple-projects-146g