How do I build different projects in the same repo with Azure Pipelines

Viewed 15

I'm new to Azure Pipelines. I have a repo in Azure DevOps that includes a Web API project, a background service and a bunch of common libraries. I'm trying to create two Pipelines to produce two different drops -- one for the API and one for the service. I don't want the code in the service drop to include any of the web api stuff and visa versa.

In my pipeline parameters, I have the specific project of either the api or the service referenced (i.e. ProjectName/*.csproj).

That is what is used for Restore, Build, etc. However, when I run either of the pipelines, I get the same result -- they both include everything in the repo. IOW, my background service project (which has no reference to the api) winds up with all the web api controllers, the web.config, etc.

Is it possible to accomplish what I'm after?

YAML API Pipeline

variables:
- name: BuildParameters.RestoreBuildProjects
  value: MyAPI/*.csproj
- name: BuildParameters.TestProjects
  value: MyAPI/*[Tt]ests/*.csproj
name: $(date:yyyyMMdd)$(rev:.r)
jobs:
- job: Job_1
  displayName: Agent job 1
  pool:
    name: Azure Pipelines
  steps:
  - checkout: self
    fetchDepth: 1
  - task: DotNetCoreCLI@2
    displayName: Restore
    inputs:
      command: restore
      projects: $(BuildParameters.RestoreBuildProjects)
  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      projects: $(BuildParameters.RestoreBuildProjects)
      arguments: --configuration $(BuildConfiguration)
  - task: DotNetCoreCLI@2
    displayName: Test
    inputs:
      command: test
      projects: $(BuildParameters.TestProjects)
      arguments: --configuration $(BuildConfiguration)
  - task: DotNetCoreCLI@2
    displayName: Publish
    inputs:
      command: publish
      publishWebProjects: True
      projects: $(BuildParameters.RestoreBuildProjects)
      arguments: --configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)
      zipAfterPublish: True
  - task: PublishBuildArtifacts@1
    displayName: Publish Artifact
    condition: succeededOrFailed()
    inputs:
      PathtoPublish: $(build.artifactstagingdirectory)
      TargetPath: '\\my\share\$(Build.DefinitionName)\$(Build.BuildNumber)'
...

YAML Backgroun Service Pipeline

variables:
- name: BuildParameters.RestoreBuildProjects
  value: MyServices/*.csproj
- name: BuildParameters.TestProjects
  value: MyServices/*[Tt]ests/*.csproj
name: $(date:yyyyMMdd)$(rev:.r)
jobs:
- job: Job_1
  displayName: Agent job 1
  pool:
    name: Azure Pipelines
  steps:
  - checkout: self
    fetchDepth: 1
  - task: DotNetCoreCLI@2
    displayName: Restore
    inputs:
      command: restore
      projects: $(BuildParameters.RestoreBuildProjects)
  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      projects: $(BuildParameters.RestoreBuildProjects)
      arguments: --configuration $(BuildConfiguration)
      workingDirectory: MyServices
  - task: DotNetCoreCLI@2
    displayName: Test
    inputs:
      command: test
      projects: $(BuildParameters.TestProjects)
      arguments: --configuration $(BuildConfiguration)
  - task: DotNetCoreCLI@2
    displayName: Publish
    inputs:
      command: publish
      publishWebProjects: True
      projects: $(BuildParameters.RestoreBuildProjects)
      arguments: --configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)
      zipAfterPublish: True
      workingDirectory: MyServices
  - task: PublishBuildArtifacts@1
    displayName: Publish Artifact
    condition: succeededOrFailed()
    inputs:
      PathtoPublish: $(build.artifactstagingdirectory)
      ArtifactName: service-drop
      TargetPath: '\\my\share\$(Build.DefinitionName)\$(Build.BuildNumber)'
...
0 Answers
Related