Last active
January 6, 2023 06:28
-
-
Save azu/533a1cfb83e1040d77b6963c9004856d to your computer and use it in GitHub Desktop.
Get Circle CI Project envars! Require Node.js 16 + `npm install node-fetch`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fetch from "node-fetch"; // Node.js 18 just remove line | |
const CIRCLECI_TOKEN = process.env.CIRCLECI_TOKEN | |
const ORG_NAME = process.env.ORG_NAME | |
const fetchProjectList = (orgName = ORG_NAME) => { | |
return fetch(`https://circleci.com/api/v2/insights/gh/${orgName}/summary`, { | |
headers: { "Circle-Token": `${CIRCLECI_TOKEN}` } | |
}).then(res => res.json()).then(json => json.all_projects); | |
}; | |
const fetchProjectEnv = (orgName, project) => { | |
return fetch(`https://circleci.com/api/v2/project/gh/${orgName}/${project}/envvar`, { | |
headers: { "Circle-Token": `${CIRCLECI_TOKEN}` } | |
}).then(res => res.json()); | |
} | |
const projectNames = await fetchProjectList(); | |
const projectMap = new Map() | |
for(const projectName of projectNames){ | |
const env = await fetchProjectEnv(ORG_NAME, projectName); | |
projectMap.set(projectName, env.items); | |
} | |
console.log(JSON.stringify(Array.from((projectMap.entries())))) |
$ CIRCLECI_TOKEN=xxx ORG_NAME=your-org node all-env-circleci.mjs
Note: insights API does not return all projects.
If you need to get all projecs, please copy these from Admin Console.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ref CircleCI-Archived/api-preview-docs#97
Ref https://circleci.com/docs/api/v2/index.html#operation/listEnvVars
Ref CircleCI security alert: Rotate any secrets stored in CircleCI