Add pipelines environment variables

I have a copilot application that contains two pipelines:

copilot/pipelines/pipeline_a/
  buildspec.yml
  manifest.yml
copilot/pipelines/pipeline_b/
  manifest.yml

Pipeline B manifest references buildspec.yml so it is shared between the two pipelines.

I manually edited the generated pipelines adding environment variables enter image description here

Is it possible to include those variables in the copilot configurations files? The most natural place would be in the pipeline manifest.yml but I couldn't find any documentation for that, and nothing I tried was visible within the buildspec.yml.

Upvotes: 1

Views: 200

Answers (2)

qosha
qosha

Reputation: 41

I can't comment, but just adding some context to jerome's answer which took me a second to get to.

  • Call copilot pipeline override --name <pipeline_name>

I had to update my copilot-cli first to get this to work so watch out for that.

This call should create a new file (one I had yet to use) under /overrides in your pipeline folder. Should be called cfn.patches.yml

In there you can add the command lines from Jerome which will set the ENV Vars.

# Delete the task role resource
# - op: remove
#   path: /Resources/TaskRole

# Add a service connect alias
# - op: add
#   path: /Resources/Service/Properties/ServiceConnectConfiguration/Services/0/ClientAliases/-
#   value:
#     Port: !Ref TargetPort
#     DnsName: yamlpatchiscool

# Replace the task role in the task definition
# - op: replace
#   path: /Resources/TaskDefinition/Properties/TaskRoleArn
#   value: arn:aws:iam::123456789012:role/MyTaskRole

This saved me a lot of time each time I deploy a new pipeline so hope it helps!

Upvotes: 1

I got an answer on copilot-cli github pages.

To quickly unblock the use case right now you can run copilot pipeline override and in your yaml patch file you can specify env vars like this

- op: add
  path: /Resources/BuildProject/Properties/Environment/EnvironmentVariables/-
  value:
    Name: VARIABLE_NAME
    Value: value_a

Upvotes: 1

Related Questions