# Semaphore

> Send VisualCI builds from Semaphore. The CLI reads the commit, branch and pull request from Semaphore's variables.

Source: https://visualci.com/docs/ci/semaphore/
All of VisualCI's documentation: https://visualci.com/llms.txt

Create a secret named `visualci` with the environment variable `VISUALCI_TOKEN` (a project token). The CLI reads the commit from `SEMAPHORE_GIT_PR_SHA` or `SEMAPHORE_GIT_SHA`, the branch from `SEMAPHORE_GIT_PR_BRANCH` or `SEMAPHORE_GIT_BRANCH`, and the pull request from `SEMAPHORE_GIT_PR_NUMBER`.

```yaml
version: v1.0
name: Tests
agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu2204
blocks:
  - name: Test
    task:
      secrets:
        - name: visualci
      jobs:
        - name: Test
          commands:
            - checkout
            - curl -fsSL https://visualci.com/install.sh | VISUALCI_VERSION=0.2.5 VISUALCI_INSTALL_DIR="$HOME/bin" sh
            - export PATH="$HOME/bin:$PATH"
            - export VISUALCI_BUILD_ID=$(visualci build create)
            - npm test -- -u # write snapshots instead of failing; see the snapshot guides
            - visualci upload --from auto src tests
            - visualci build finalize
```

## Parallelism

With `parallelism: <n>`, every job creates the build with the workflow's id and finalizes its own shard. Semaphore numbers jobs from 1, VisualCI from 0:

```sh
export VISUALCI_BUILD_ID=$(visualci build create --nonce "$SEMAPHORE_WORKFLOW_ID" --shards "$SEMAPHORE_JOB_COUNT")
# ... tests and uploads ...
visualci build finalize --shard "$((SEMAPHORE_JOB_INDEX - 1))"
```

See [Other CI providers](https://visualci.com/docs/ci/other.md) for the environment variables and how shards work.
