How to Set Action Secrets Programmatically

Last Updated: Jul 15, 2024

Overview

This article describes how to set action secrets programmatically.

Solution

The Action secrets can be updated in two steps.

The Action secrets can be updated in two steps.

  1. Call the Patch Action API with the secret payload:

{
“secrets”: [
{“name”: “secret1”, “value”: “super-secret-1”},
{“name”: “secret2”, “value”: “super-secret-2”},
]
}

If only some of the secrets have to be updated while preserving others, the secrets that need to be preserved must be in the payload without the value section.

E.g., the value of secret1 is preserved, and secret2 is updated with a new secret:

{
“secrets”: [
{“name”: “secret1”}, {“name”: “secret2”, “value”: “new-secret-for-secret-2”},
]
}

  1. Call the Deploy Action API to activate the changes.

NOTE: Updating the Action secrets from within Actions is not recommended.