//native
type Circleci = {
token: string
}
/**
* Add or update an environment variable
* Create or update an environment variable within a context. Returns information about the environment variable, not including its value.
*/
export async function main(
auth: Circleci,
context_id: string,
env_var_name: string,
body: { value: string }
) {
const url = new URL(
`https://circleci.com/api/v2/context/${context_id}/environment-variable/${env_var_name}`
)
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Circle-Token': auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 536 days ago