2

I would like to conditionally execute certain stage in AWS Codepipeline depending on that if I put certain file on repo location. So, if I put "some_file.txt" on certain location in repo, I want for Codepipeline to check existence of this file and if it's there continue further to deploy code to production, otherwise stop on that stage.

With this I would like to avoid manual approval action and control release process with committing a file. Is this possible and what would be best practice?

datahack
  • 477
  • 1
  • 11
  • 32

2 Answers2

3

I think you could create a lambda action for that:

The lambda function can access the input artifact, and check if your file of interest is there or not.

Depending on the outcome of the check, the function with either put_job_success_result or put_job_failure_resul to continue or stop the pipeline.

Marcin
  • 215,873
  • 14
  • 235
  • 294
1

you can use the spec file to check if there's the needed file present. If not, then you can execute a "stop-pipeline-execution" https://docs.aws.amazon.com/cli/latest/reference/codepipeline/stop-pipeline-execution.html

command. The required args can be fetched from the env vars and one more thing to note is to give that stage of yours adequate permission(s) to be able to execute the command.

Muhammad Hasan
  • 140
  • 1
  • 9
  • To check for file in artifact and then execute cli command from codebuild to stop execution? That's a nice solution. I found out i can also break codebuild stage by executing command - exit 1 – datahack Aug 08 '20 at 17:07
  • 1
    yes. or to explicitly break pipeline simply run an invalid command e.g cd/nonExistentFolder – Muhammad Hasan Aug 08 '20 at 17:21