|
| 1 | +--- |
| 2 | +title:"How To: Automate creation of Shared Secrets" |
| 3 | +description: |
| 4 | +group:kb |
| 5 | +sub-group:articles |
| 6 | +toc:true |
| 7 | +kb:false |
| 8 | +ht:true |
| 9 | +common:false |
| 10 | +categories:[Pipelines, CLI] |
| 11 | +support-reviewed:2024-01-17 MB |
| 12 | +--- |
| 13 | + |
| 14 | +##Overview |
| 15 | + |
| 16 | +You have numerous secrets to manage across different pipelines and want to make the process more efficient. |
| 17 | + |
| 18 | +##Details |
| 19 | + |
| 20 | +The script reads each line from the provided file and appends it to the Codefresh`create context secret` command. This results in a single command that creates a secret context with all the specified secrets. |
| 21 | + |
| 22 | +>**NOTE** |
| 23 | +Ensure you have the necessary permissions to create contexts in Codefresh. |
| 24 | + |
| 25 | +**Script** |
| 26 | + |
| 27 | +```bash |
| 28 | +#!/bin/bash |
| 29 | + |
| 30 | +CMD="codefresh create context secret <secret_context_name>" |
| 31 | + |
| 32 | +whileread LINE;do |
| 33 | + |
| 34 | +CMD="${CMD} -v${LINE}" |
| 35 | + |
| 36 | +done<"$1" |
| 37 | + |
| 38 | +echo"$CMD" |
| 39 | +``` |
| 40 | + |
| 41 | +**How to use the script** |
| 42 | + |
| 43 | +1. Prepare your secrets list |
| 44 | + Start by preparing a file containing your secrets. Each line in the file should contain one secret in the format KEY=VALUE. |
| 45 | + |
| 46 | +2. Set execution permissions |
| 47 | + Make the script executable by running: |
| 48 | +`chmod +x script_name.sh` |
| 49 | + |
| 50 | +3. Run the script |
| 51 | + Execute the script with the command: |
| 52 | +`./script_name.sh secret_list.txt` |
| 53 | + where: |
| 54 | +`secret_list.txt` is the file containing your secrets |
| 55 | + |
| 56 | +4. Verify creation |
| 57 | + After executing the script, verify that the secret context has been created in Codefresh with the specified secrets. |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +##Related articles |
| 62 | +[Secrets in pipelines]({{site.baseurl}}/docs/pipelines/configuration/secrets-store/) |
| 63 | +[Configuring access control for pipelines]({{site.baseurl}}/docs/administration/account-user-management/access-control/) |
| 64 | +[Pipeline execution context]({{site.baseurl}}docs/administration/account-user-management/pipeline-execution-context/) |