0

I am triggering AWS CodePipeline with a PR commit through Bitbucket. Is there any way I can find which files were updated/created with the latest commit?

I looked into the Environment Variables and I looked into the pipeline's details and history CLI commands: $ aws codepipeline list-pipeline-executions --pipeline-name <name> and $ aws codepipeline get-pipeline-state --name <name> but they don't have the information I need.

Why do I need this? The pipeline triggers one or more Airflow DAGs and listens to their status. We include the DAG name(s) in the branch name, we parse it using CODEBUILD_WEBHOOK_HEAD_REF and we trigger the DAG(s). This is error-prone, and since the DAG names match their filename we would like to extract them automatically.

Is it something doable? Thanks for your help!

Diana Kerrala
  • 77
  • 1
  • 7
  • 1
    Where would you like to find the diff? As a build for the PR, or in the build after merging? Any way `git diff` can be of help? See also https://stackoverflow.com/questions/9903541/finding-diff-between-current-and-last-version. Make sure you use the full clone version of codepipeline: https://stackoverflow.com/questions/47310000/aws-codepipeline-build-lacks-git-history. Didn't try it myself though – LRutten Sep 07 '21 at 15:21
  • I would like to get it during the build for the PR. I'll test if I can use `git diff`. Thank you for your answer! – Diana Kerrala Sep 08 '21 at 07:26

1 Answers1

3

You can get the commit hash from the pipeline execution. when using cli:

aws codepipeline list-pipeline-executions --pipeline-name <pipeline-name>

you get a list of executions, the first execution is the latest one.

pipelineExecutionSummaries: [ 
    { ...
       sourceRevisions: [
         {
             ...
             revisionId: "<commit-hash>"
          }
        ]
    }
...
]

then when you have the commit hash you can get the files that are modified in that commit

git diff-tree --stat <commit-hash>

further logic depending on your application you can handle when you got the files that are modified.

Lucasz
  • 1,150
  • 9
  • 19