Azure DevOps Task: Changed Files
Pipeline task to get changed files and apply conditions according to those changes.
Installation
Installation can be done using Visual Studio MarketPlace.
Source Code
Source code can be found on Github.
Simple Usage
jobs:
- job: check
displayName: Check changed files
pool:
vmImage: ubuntu-latest
steps:
- task: ChangedFiles@1
name: CheckChanges
inputs:
rules: src/**/*.ts
variable: HasChanged
- job: build
displayName: Build only when code changes
dependsOn: check
condition: eq(dependencies.check.outputs['CheckChanges.HasChanged'], 'true')
steps:
- # Add your build steps here
Multiple variable Usage
jobs:
- job: check
displayName: Check changed files
pool:
vmImage: ubuntu-latest
steps:
- task: ChangedFiles@1
name: CheckChanges
inputs:
rules: |
[CodeChanged]
src/**/*.ts
src/**/*.html
[TestsChanged]
tests/**/*.ts
- job: build
displayName: Build only when code changes
dependsOn: check
condition: eq(dependencies.check.outputs['CheckChanges.CodeChanged'], 'true')
steps:
- # Add your build steps here
- job: tests
displayName: Tests only when code changes or tests changes
dependsOn: check
condition: or(eq(dependencies.check.outputs['CheckChanges.CodeChanged'], 'true'), eq(dependencies.check.outputs['CheckChanges.TestsChanged'], 'true'))
steps:
- # Add your build steps here
Multiple branches Usage
jobs:
- job: check
displayName: Check changed files
pool:
vmImage: ubuntu-latest
steps:
- task: ChangedFiles@1
name: CheckChanges
inputs:
refBranch: master
rules: |
[CodeChanged]
src/**/*.ts
src/**/*.html
[TestsChanged]
tests/**/*.ts
- job: build
displayName: Build only when code changes
dependsOn: check
condition: eq(dependencies.check.outputs['CheckChanges.CodeChanged'], 'true')
steps:
- # Add your build steps here
- job: tests
displayName: Tests only when code changes or tests changes
dependsOn: check
condition: or(eq(dependencies.check.outputs['CheckChanges.CodeChanged'], 'true'), eq(dependencies.check.outputs['CheckChanges.TestsChanged'], 'true'))
steps:
- # Add your build steps here
Options
- rules: Filter files to check changes for. Default:
**
(match all files).
- variable: The name of the default output variable to set to be available in next steps/jobs/stages. Default:
HasChanged
.
- isOutput: Are variables available in next stages? Default:
true
.
- refBranch: The branch that will be used as reference to check changes in case multi-branches pipeline.
- cwd: Change the current working directory. Default:
$(System.DefaultWorkingDirectory)
- verbose: Enable verbose logging. Default:
false
.
License
MIT
Git tested changes
- [x] git repo with only one branch or a pipeline for only one branch
- [x] git create new branch without changes vs reference branch
- [x] git push with single commit
- [x] git push with several commits
- [x] git repo with multiple branches and a pipline for multiple branches
- [x] git merge a branch into another branch
- [x] git cherry-pick
- [x] git rebase and push force
- [x] git revert