Search code examples
bashjqaws-cliaws-codepipeline

Get a list of AWS pipelines ready for stage approval


I have 40+ pipelines that I need to approve from dev to QA and then QA to stage. I am working on a script to use AWS CLI commands to do do. I have been able to do that for a single pipeline where I know that the specific pipeline is ready to be approved.

aws codepipeline put-approval-result --cli-input-json file://TestPipeline.json 

This is how I gathered the information for the approval for a single pipeline

aws codepipeline get-pipeline-state --name Pipeline-Ready-for-Approval 

What I am trying to find out is - is there a way to loop through all of the pipelines using the get-pipeline-state and identify the stage name and action name without manually going through output of each of the pipelines.

I can try to get the pipeline names from aws codepipeline list-pipelines to get the list to loop through.

Is it possible using bash script and awscli and jq together?

Thank you


Solution

  • You can get most of the way there using the following

    export pipelines=$(aws codepipeline list-pipelines --query 'pipelines[].name' --output text)
    
    for p in $pipelines; do
        aws codepipeline get-pipeline-state \
            --name $p \
            --query 'stageStates[?latestExecution.status==`InProgress`].{stageName:stageName,actionName:actionStates[0].actionName,token:actionStates[0].latestExecution.token}'
    done
    

    This assumes the approval action exists as the first or only action within a stage.

    You'll get the output required for the put-approval-result command