{"id":19633285,"url":"https://github.com/quipper/circleci-env","last_synced_at":"2025-04-28T07:30:47.886Z","repository":{"id":54682405,"uuid":"78558204","full_name":"quipper/circleci-env","owner":"quipper","description":"circleci-env is a tool to manage CircleCI Environment Variables.","archived":false,"fork":false,"pushed_at":"2022-10-07T15:09:41.000Z","size":92,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":145,"default_branch":"master","last_synced_at":"2025-04-05T07:33:00.910Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quipper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-10T17:45:02.000Z","updated_at":"2022-11-21T08:18:09.000Z","dependencies_parsed_at":"2023-01-19T14:15:58.464Z","dependency_job_id":null,"html_url":"https://github.com/quipper/circleci-env","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Fcircleci-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Fcircleci-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Fcircleci-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Fcircleci-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quipper","download_url":"https://codeload.github.com/quipper/circleci-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251271082,"owners_count":21562487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T12:16:54.899Z","updated_at":"2025-04-28T07:30:46.809Z","avatar_url":"https://github.com/quipper.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# circleci-env\n\n`circleci-env` is a tool to manage CircleCI Environment Variables and Settings using CircleCI API.\n\n\u003c!-- TOC depthFrom:2 --\u003e\n\n- [Installation](#installation)\n- [Supported Settings](#supported-settings)\n- [Usage](#usage)\n- [Envfile examples](#envfile-examples)\n  - [For single project](#for-single-project)\n  - [For multiple project](#for-multiple-project)\n    - [Envfile](#envfile)\n    - [For each project](#for-each-project)\n- [Secret variables](#secret-variables)\n  - [Project structure](#project-structure)\n  - [Write secret variable](#write-secret-variable)\n  - [Read secret variable](#read-secret-variable)\n  - [List all secret variables](#list-all-secret-variables)\n  - [Change password](#change-password)\n- [Export existing project's envvars](#export-existing-projects-envvars)\n  - [Export all projects which you can access](#export-all-projects-which-you-can-access)\n  - [Export single project](#export-single-project)\n  - [Export projects which muched by by filter](#export-projects-which-muched-by-by-filter)\n  - [Export folder structure](#export-folder-structure)\n- [Development](#development)\n- [Contributing](#contributing)\n- [License](#license)\n\n\u003c!-- /TOC --\u003e\n\n## Installation\n\nFirst, download the source:\n\n```ruby\n$ git clone git@github.com:quipper/circleci-env.git\n```\n\nBuild the gem:\n\n```sh\n$ cd circleci-env \u0026\u0026 gem build circleci-env.gemspec\n```\n\nInstall it (the filename/version may vary)\n\n```sh\n$ gem install circleci-env-0.3.1.gem\n```\n\n## Supported Settings\n\n- [Environment Variables](https://circleci.com/docs/environment-variables/#setting-environment-variables-for-all-commands-without-adding-them-to-git)\n- [SSH Keys](https://circleci.com/docs/api/#ssh-keys)\n\n## Usage\n\n```sh\n$ circleci-env --help\n  circleci-env\n\n  circleci-env is a tool to manage CircleCI environment variables.\n\n  Commands:\n    apply        Apply CircleCI environment variables from config files\n    export       Export CircleCI environment variables from API\n    help         Display global or [command] help documentation\n    shell-export Shew a shell expression to export all environment variables on a project\n    vault list   List all secret variables\n    vault read   Read secret variable\n    vault rekey  Change password of all secret variables\n    vault write  Write secret variable\n\n  Global Options:\n    -h, --help           Display help documentation \n    -v, --version        Display version information \n    -t, --trace          Display backtrace when an error occurs \n```\n\n```sh\n$ export CIRCLECI_TOKEN='...'\n$ vi Envfile.rb\n$ circleci-env apply -c Envfile.rb --dry-run\n$ circleci-env apply -c Envfile.rb\n```\n\nEnvfile.rb is like this:\n\n```rb\nproject \"github/username/repot-01\" do\n  env(\n    \"KEY1\" =\u003e \"XYZ\",\n    \"KEY3\" =\u003e \"ABCDEF\",\n    \"SECRET_KEY1\" =\u003e secret(\"secret_key1\")\n  )\n  ssh_key(\n    \"test1.example.com\" =\u003e secret(\"ssh_key1\"),\n    \"test3.example.com\" =\u003e secret(\"ssh_key3\"),\n  )\nend\n```\n\nCommand output is like this:\n\n```sh\nLoad config from Envfile.rb\nApply Envfile.rb to CircleCI\n\n=== github/username/repo1\n\nProgress: |\nenvvars:\n  + add    KEY1=XYZ\n  - delete KEY2\n  ? update SECRET_KEY1=xxxxQ\n  ~ update KEY3=ABCDEF\nssh_keys:\n  + add    test1.example.com=\u003cssh key fingerprint\u003e\n  - delete test2.example.com=\u003cssh key fingerprint\u003e\n  ~ update test3.example.com=\u003cssh key fingerprint\u003e\n\nResult: |\nenvvars:\n  KEY1=xxxxZ\n  SECRET_KEY1=xxxxQ\n  KEY3=xxxxEF\nssh_keys:\n  test1.example.com=\u003cssh key fingerprint\u003e\n  test3.example.com=\u003cssh key fingerprint\u003e\n```\n\nThere are 4 progress statuses\n\n- `+ add`: Add new environment variable\n- `- delete`: Delete existing environment variable\n- `? update`: Suffix matches current value. Maybe value is not update.\n- `~ update`: Update existing environment variable\n\n`? update` is tricky status, but it's depends on CircleCI REST API specification.\nCircleCI REST API return only masked value (show few character of raw value),\nso we cannot match exactly between current and new values.\n\n## Envfile examples\n\n### For single project\n\n```rb\nproject \"github/user/repo\" do\n  env(\n    \"KEY1\" =\u003e \"value1\",\n    \"KEY2\" =\u003e \"Value2\",\n  )\nend\n```\n\n### For multiple project\n\n`circleci-env` recommends to use following project structure.\n\n```\n|- Envfile\n|- projects\n   |- github\n      |- user\n      |  |- repo1.rb\n      |  |- repo2.rb\n      |\n      |- organization\n         |- repo3.rb\n```\n\n#### Envfile\n\n```rb\n#\n# If you want to write common setting, write here\n#\n\nDir[File.expand_path('../projects', __FILE__) + '/**/*.rb'].each do |file|\n  require file\nend\n```\n\n#### For each project\n\n```rb\nproject \"github/user/repo1\" do\n  env(\n    \"KEY1\" =\u003e \"value1\",\n    \"KEY2\" =\u003e \"value2\",\n  )\nend\n```\n\n```rb\nproject \"github/user/repo2\" do\n  env(\n    \"KEY1\" =\u003e \"value1\",\n    \"KEY2\" =\u003e \"value2\",\n  )\nend\n```\n\nYou can see real example in [examples](./examples) folder.\n\n## Secret variables\n\n`circleci-env` support vault feature to manage secret values like API key.\nYou can read/write encrypted secret value and refer it as variable in `Envfile.rb`.\n\n### Project structure\n\n```\n|- Envfile\n|- secret\n   |- secret_key.vault\n   |- some_api_token.vault\n   |- ...\n```\n\nAll secret variables are stored in file in a directory named `secret`, or you can specify any directory with the environment variable `CIRCLECI_ENV_SECRET_DIR`.\nEach file includes a value of the secret and must have `.vault` file extension.\n\nIn `Envfile.rb`, you can refer to these variables by filename without extension using `secret` method.\nFor example, you can refer secret value in `secrete_key.vault` like:\n\n```rb\nproject \"github/user/repo1\" do\n  env(\n    \"NORMAL_KEY\" =\u003e \"value1\",\n    \"SECRET_KEY\" =\u003e secret(\"secret_key\")\n  )\n  ssh_key(\n    \"host1.example.com\" =\u003e secret(\"sshkey-host1-example-com\"),\n    \"host2.example.com\" =\u003e secret(\"sshkey-host2-example-com\"),\n  )\nend\n```\n\n### Write secret variable\n\nTo encrypt secret variable and write it to file, use `vault write` command.\n\n```sh\n$ export CIRCLECI_ENV_PASSWORD=xxx\n$ circleci-env vault write secret_key \"Some secret value\"\n```\n\nTo write secret variable via file, use `--input-file` option.\n\n```sh\n$ export CIRCLECI_ENV_PASSWORD=xxx\n$ circleci-env vault write secret_key --input-file secret_file\n```\n\nThis command encrypt values and write it into a file named `secret_key.vault` in `secret` directory.\n\n### Read secret variable\n\nTo decrypt secret variable from, use `vault read` command.\n\n```sh\n$ export CIRCLECI_ENV_PASSWORD=xxx\n$ circleci-env vault read secret_key\n#=\u003e \"Some secret value\"\n```\n\nThis command read a secret variable from `secret_key.vault` in `secret` directory.\n\n### List all secret variables\n\nTo list all secret variables, use `vault list` command.\n\n```sh\n$ export CIRCLECI_ENV_PASSWORD=xxx\n$ circleci-env vault list                                                                                                                                                                                                 (git)-[master] -\n=== Secret Vars\nkey1: value1\nkey2: value2\n```\n\n### Change password\n\nTo change password of all secret variables, use `vault rekey` command.\n\n```sh\n$ circleci-env vault rekey\nCurrent Password: ***\nNew Password: ***\n\n=== Rekey Secret Variables\nRekey key1\nRekey key2\n```\n\n## Export existing project's envvars\n\n`circleci-env` provide command to export existing project's envvars.\nUnfortunately CircleCI API returns masked value, you cannot get raw value of envars.\nSo you have to update all values in config file before apply it.\n\n### Export all projects which you can access\n\n```sh\n$ circleci-env export\n```\n\n### Export single project\n\n```sh\n$ circleci-env export --filter \"github/username/repo\"\n```\n\n### Export projects which muched by by filter\n\nYou can filter projects by regular expression\n\n```sh\n$ circleci-env export --filter \"^github\\/username\\/.*$\"\n```\n\n### Export folder structure\n\nExport feature create a file per projects following folder structure like this:\n\n```\n|- projects\n   |- github\n      |- user\n      |  |- repo1.rb\n      |  |- repo2.rb\n      |\n      |- organization\n         |- repo3.rb\n```\n\n## Show a shell expression to export all environment variables on a project. \n`circleci-env` can show all environment variables on a project as a shell export's expression.\n\n```sh\n$ export CIRCLECI_ENV_PASSWORD=xxx\n$ circleci-env shell-export github/username/repo\nexport KEY1='VALUE1'\nexport KEY2='VALUE2'\nexport KEY3='VALUE3'\n```\n\nSo you can export them with `eval`\n\n```sh\n$ eval \"$(circleci-env shell-export github/username/repo)\"\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/quipper/circleci-env.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquipper%2Fcircleci-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquipper%2Fcircleci-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquipper%2Fcircleci-env/lists"}