Instantly share code, notes, and snippets.
Last activeJanuary 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 hidden or 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
importfetchfrom"node-fetch";// Node.js 18 just remove line | |
constCIRCLECI_TOKEN=process.env.CIRCLECI_TOKEN | |
constORG_NAME=process.env.ORG_NAME | |
constfetchProjectList=(orgName=ORG_NAME)=>{ | |
returnfetch(`https://circleci.com/api/v2/insights/gh/${orgName}/summary`,{ | |
headers:{"Circle-Token":`${CIRCLECI_TOKEN}`} | |
}).then(res=>res.json()).then(json=>json.all_projects); | |
}; | |
constfetchProjectEnv=(orgName,project)=>{ | |
returnfetch(`https://circleci.com/api/v2/project/gh/${orgName}/${project}/envvar`,{ | |
headers:{"Circle-Token":`${CIRCLECI_TOKEN}`} | |
}).then(res=>res.json()); | |
} | |
constprojectNames=awaitfetchProjectList(); | |
constprojectMap=newMap() | |
for(constprojectNameofprojectNames){ | |
constenv=awaitfetchProjectEnv(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 freeto join this conversation on GitHub. Already have an account?Sign in to comment