1

(also wondering if the solution is available in classic as well as YAML mode)

The purpose of this requirement is trying to grow a pipeline template instead of having duplicates of PR/CI/Release with only difference in the path of a branch

For example, considering following project structure

Repository (MyApp)
    |
    |- com.123abc.myapp.prj01   ==> PR pipeline ==> CI pipeline ==> Release pipeline 
    |
    |- com.456abc.myapp.prj02   ==> PR pipeline ==> CI pipeline ==> Release pipeline 
    |
    |- com.789abc.myapp.prj03   ==> PR pipeline ==> CI pipeline ==> Release pipeline 
    |
    |- com.000abc.myapp.prj04   ==> PR pipeline ==> CI pipeline ==> Release pipeline 
    |

In reality prj01.. prj04 can have little difference in project structure however have different environment for deployment. So PR/CI/Release pipeline is pretty much the same with a couple parameter with dynamic value.

So here are my questions:

  1. I understand that group variables is the feature that can be used for those parameters, however how to trigger pipeline with dynamic Path filter that I can create single set of PR/CI/Release pipelines that can serve each prj0n

  2. Is there a way to pass external parameter into PR/CI/Release pipeline respectively other than variable group?

Thanks much in advance.

Dreamer
  • 7,333
  • 24
  • 99
  • 179

1 Answers1

0

How to dynamically trigger PR/CI/Release pipeline in Azure DevOps based on project directory

You could try to use the git command to get the project directory path of the project change, like:

# Checks which files have been updated to determine build/release the job
$editedFiles = git diff HEAD HEAD~ --name-only
echo "$($editedFiles.Length) files modified:"
$editedFiles | ForEach-Object {
   echo $_
    Switch -Wildcard ($_ ) {
        'com.123abc.myapp.prj01/*' { 
              Write-Output "##vso[task.setvariable variable=ChangeThePrj01;isOutput=true]True"
         }        
        'com.456abc.myapp.prj02/*' { Write-Output "##vso[task.setvariable 
variable=ChangeThePrj02;isOutput=true]True" }
        'com.456abc.myapp.prj03/*' { Write-Output "##vso[task.setvariable 
variable=ChangeThePrj03;isOutput=true]True" }
        'com.456abc.myapp.prj04/*' { Write-Output "##vso[task.setvariable 
variable=ChangeThePrj04;isOutput=true]True" }
    }
}

Then we could use the Output variables from previous job/stages for the deplot:

`dependencies.jobName.outputs['stepName.variableName']`,stages refer to `stageDependencies.stageName.jobName.outputs['stepName.variableName']`

like:

jobs:
- deployment: prj01
  displayName: DeployForprj01
  pool: 
    name: string
  condition: eq(dependencies.jobName.outputs['stepName.ChangeThePrj01'], 'True')
  steps:
    - script: echo "Deploy Forprj01."


- deployment: prj02
  displayName: DeployForprj02
  pool: 
    name: string
  condition: eq(dependencies.jobName.outputs['stepName.ChangeThePrj02'], 'True')
  steps:
    - script: echo "Deploy Forprj02."

You could check the thread and the document Specify conditions for some more details.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135