3

I'm new to codepipeline & I have multiple actions in a build stage in codepipeline, which 1 buildspec similar to below , and i want to dynamically create a variable here in the python file which i need for a downstream action.

version: 1
phases:
  install:
    runtime-version:
      python: 3.9
    commands:
      - python -m pip install --upgrade pip 
  build:
    commands:
      - python code/get_date.py

get_date.py

import datetime
if __name__ == "__main__":
    current_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())

Then I have a second buildspec file which runs in the second action

version: 1
phases:
  install:
    runtime-version:
      python: 3.9
    commands:
      - python -m pip install --upgrade pip 
  build:
    commands:
      - python code/process_date.py

process_date.py

if __name__ == "__main__":
    # get current date somehow from previous action
    print(current_date)

How do I accomplish something like this? And what is the best recommendation? Would i use output artifacts or variables? And how are they used to pass values like this between stages?

Any help greatly appreciated.

0

1 Answer 1

6

CodeBuild can output variables to be used in other stages or actions in your CodePipeline. These variables are called CodeBuild action output variables and are defined using env/exported-variables in your buildspec.yml.

General info how to consume and use these variables in a CP are described in Working with variables AWS docs.

Sign up to request clarification or add additional context in comments.

2 Comments

How do these variables get created for export in the python script in codebuild? Do i need to do anything to write to an environment variable?
@ersh Did you read the docs? It explains you have to define them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.