Run CI
refs CI runs the jobs of a pipeline in containers on Cloudflare. A pipeline runs on a push, on a pull request, or when you start it. This document shows you how to add a pipeline, keep secrets, and protect deploys.
For each key of the pipeline file, see CI configuration.
Before you begin
- Have write access to the repository.
Add a pipeline
In the repository, create the file
.refs/ci.yml:on: push: branches: [main] pull_request: manual: jobs: test: image: node timeout_minutes: 20 steps: - name: Install run: npm ci - name: Test run: npm testCommit and push the file.
The push to main starts a run. Open the Runs tab of the repository to see it. A dot next to the last commit shows the result of its run.
How a run works
- refs reads
.refs/ci.ymlat the commit. If the file is not valid, the run fails and lists each problem with the path of the key. - refs starts each job whose
needsjobs succeeded. Jobs withoutneedsstart at once. - Each job checks out the commit in a new container, then runs its steps in order with
bash. - A failed step stops the job. A job that fails, is skipped, is cancelled or times out makes each job that needs it skip.
Each job gets these environment variables: CI=true, REFS_SHA, REFS_REF, REFS_JOB and REFS_RUN_ID.
refs runs at most 2 job containers at the same time across the server. Other jobs wait in the queue.
Start a run by hand
If the pipeline has the manual trigger:
- Open the Runs tab.
- In Branch, select a branch.
- Click Start run.
To stop a run, open it and click Cancel run. To run a finished run again, open it and use the button next to the run title.
Trusted and untrusted runs
refs decides if a run is trusted from who started it, not from the branch. An agent can change .refs/ci.yml, so a run that an agent starts is untrusted.
| Run started by | Trust | Secrets |
|---|---|---|
| A person, push to a protected branch | Trusted | Organization, repository and environment secrets |
| A person, push to a different branch | Trusted | Organization and repository secrets |
| A person, pull request from the same repository | Trusted | Organization and repository secrets |
| A person, manual start | Trusted | Same as a push to that branch |
| An agent push, an agent pull request or an agent start | Untrusted | None |
| A pull request from a fork | Untrusted | None |
An untrusted run shows This run is untrusted with the reason. Its jobs get no secrets, and each job with an environment waits for a person.
Add secrets
A job gets only the secrets that it names in its secrets key, as environment variables. refs stores each value sealed. Nobody can read a value back, and refs masks it in the logs.
To add a repository secret:
- Open the repository and click Settings.
- In Name, enter a name in capital letters, digits and
_, for exampleNPM_TOKEN. - Optional: In Scope, select an environment.
- In Value, paste the value.
- Click Save secret.
To share a secret with all repositories of a namespace, go to CI secrets in the sidebar. A repository secret with the same name wins over an organization secret. An environment secret wins over both.
Protect deploys with environments
An environment holds the rules for a deploy, for example production. A job joins an environment with the environment key.
- Open the repository and click Settings.
- Click Environments.
- In the environment form, enter a name in Name.
- Optional: In Branches that may deploy, enter branch patterns, for example
main, release/**. Leave it empty to allow each branch. - Optional: In Wait before a deploy (minutes), enter a delay.
- Keep A person approves each deploy selected to make each deploy wait for a person.
- Click Create environment.
When a job with an environment is ready, refs checks these rules in order:
- If the environment does not exist, the job does not run.
- If the branch does not match the allowed patterns, the job does not run.
- If the run is untrusted, or the environment requires approval, the job waits. A person with write access clicks Approve or Reject on the run page.
Environment secrets go only to a job in a trusted run that a person approved, or to a job in a run from a push by a person to a protected branch.
Protect branches
A protected branch gives a push by a person access to environment secrets without an approval.
- Open Settings.
- In Branch patterns, one per line, enter patterns, for example
mainandrelease/**. - Click Save protected branches.
In a pattern, * matches inside one path segment, and ** matches across segments.
What's next
- CI configuration: each key, its default and its limit.
- Permissions and limits.