0
votes

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!

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 stackoverflow.com/questions/9903541/…. Make sure you use the full clone version of codepipeline: stackoverflow.com/questions/47310000/…. Didn't try it myself thoughLRutten
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

1 Answers

2
votes

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.