Set a variable
Give GitHub-syntax workflows plain configuration values as vars.NAME, for the organization, a repository or an environment.
A workflow under .github/workflows/ reads a variable as ${{ vars.NAME }}. A variable is plain
text: it is shown to whoever may list variables and is not masked in logs, so keep anything secret
in a secret instead (see Give a job a secret). Workflows in the native
format have no vars.
Replace repo-id with the repository's id, production with an environment's name and DEPLOY_REGION with the variable's name.
Prerequisites
ci:PutVariableto create or change a variable,ci:ListVariablesto list them,ci:DeleteVariableto delete one. Organization variables are checked on all of CI (rn:ews::<organization id>:ci:*); repository and environment variables on the repository (rn:ews::<organization id>:ci:repository/<repository id>).- For an environment variable, the environment exists (see Protect a deployment with an environment). Setting a variable does not create it.
Set the variable
A name has letters, digits and _, does not start with a digit or with GITHUB_, and has up to 100
characters; it is stored upper-case. A value has up to 48 KiB.
The console has no page for variables.
# for every repository of the organization
dcloud ci variables put-org DEPLOY_REGION --value de1
# for one repository
dcloud ci variables put repo-id DEPLOY_REGION --value de1
# for one environment of a repository
dcloud ci variables put-environment repo-id production DEPLOY_REGION --value de1PUT /ci/api/repositories/repo-id/variables/DEPLOY_REGION
{ "value": "de1" }For the organization, PUT /ci/api/variables/DEPLOY_REGION; for an environment,
PUT /ci/api/repositories/repo-id/environments/production/variables/DEPLOY_REGION.
Result
The answer is 200 with { name, value, updatedAt }, whether the variable was created or changed.
From the next run on, a job reads it. When the same name is set at several levels, a job in an
environment reads the environment's value, then the repository's, then the organization's.
400with a message naming the rule, such asnames may not start with GITHUB_, when the name breaks it.400withissueswhen the body has no stringvalueor the value is longer than 48 KiB.404"No such environment" when the repository has no environment of that name;404"Not found" when the repository is not in your organization.
List or delete variables
dcloud ci variables list repo-id
dcloud ci variables delete repo-id DEPLOY_REGIONA repository's list holds its own variables, not the organization's. Deleting a name that is not
there answers 404. Deleting an environment deletes its variables with it.
Related
Related
- PUT /ci/api/variables/{variable}
- PUT /ci/api/repositories/{repoId}/variables/{variable}
- PUT /ci/api/repositories/{repoId}/environments/{name}/variables/{variable}
- GET /ci/api/variables
- GET /ci/api/repositories/{repoId}/variables
- GET /ci/api/repositories/{repoId}/environments/{name}/variables
- DELETE /ci/api/variables/{variable}
- DELETE /ci/api/repositories/{repoId}/variables/{variable}
- DELETE /ci/api/repositories/{repoId}/environments/{name}/variables/{variable}