# getModifiedFunctions

> ⚠️ **Deprecated:** Use [MonorepoUtils](../src/com/sonymusic/MonorepoUtils.groovy) for most purposes or [getModifiedPaths](getModifiedPaths.md) for bespoke usecases.

The `getModifiedFunctions` function is used to determine which functions in a set of directories have been modified based on the current Git branch and previous successful Git commit. This function is used in Jenkins pipeline scripts to identify which parts of a codebase need to be built or tested.

The branch treated as the trunk is configurable via `mainBranch` (defaults to `master`).

* If `branchName` equals `mainBranch` and `previousSuccessfulCommit` is null, returns all the provided paths.
* If `branchName` is not `mainBranch` and `previousSuccessfulCommit` is null, returns the paths which have changed relative to the common ancestor of the provided branch and `mainBranch`
* If `branchName` is not `mainBranch` and `previousSuccessfulCommit` is not null, returns the paths which have changed relative to `baseCommit`.

## Parameters

| Name                     | Description                                                                                         | Type        | Default                                                                | Required |
|--------------------------|-----------------------------------------------------------------------------------------------------|-------------|------------------------------------------------------------------------|----------|
| branchName               | The name of the current Git branch.                                                                 | `String`    | The value of the `BRANCH_NAME` environment variable                    | no       |
| lambdaDirectories        | A list of directories containing Dockerfiles for the functions you want to check for modifications. | `List<Map>` | -                                                                      | yes      |
| previousSuccessfulCommit | The SHA-1 hash of the previous successful Git commit.                                               | `String`    | The value of the `GIT_PREVIOUS_SUCCESSFUL_COMMIT` environment variable | no       |
| mainBranch               | The name of the repository's trunk branch (e.g. `master` or `main`).                                | `String`    | `master`                                                               | no       |

## Examples

```groovy
pipeline {
   stages {
      stage('Find Modified Functions') {
         steps {
            script {
               def lambdaDirectories = findFiles(glob: 'lambda/**/Dockerfile')
               def modifiedFunctionList = getModifiedFunctions(lambdaDirectories, env.BRANCH_NAME, env.GIT_PREVIOUS_SUCCESSFUL_COMMIT)
            }
         }
      }
      // Additional stages...
   }
   post {
      always {
         script {
            // Use modifiedFunctionList as needed...
         }
      }
   }
}
