Created
March 6, 2024 11:35
-
-
Save nathmahale/98c10a35561a380fae1af6c7a0454c7e to your computer and use it in GitHub Desktop.
Get pipeline execution ID from Codebuild | untested
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from boto3 import client | |
import jmespath | |
import os | |
codepipeline_client = client('codepipeline') | |
codepipeline_name = (os.environ['CODEBUILD_INITIATOR'], 'codepipeline/') | |
pipeline_response = codepipeline_client.get_pipeline_state( | |
name="".join(codepipeline_name) | |
) | |
# stageStates[?actionStates[?latestExecution.externalExecutionId=='codebuild-demo-project:b1e6661e-e4f2-4156-9ab9-82a19EXAMPLE']].latestExecution.pipelineExecutionId | |
jmespath_search_expression = ('stageStates[?actionStates[?latestExecution.externalExecutionId=="', | |
os.environ['CODEBUILD_BUILD_ID'], '"]].latestExecution.pipelineExecutionId') | |
pipeline_execution_id = jmespath.search( | |
expression="".join(jmespath_search_expression), | |
data=pipeline_response) | |
print(pipeline_execution_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment