|
| 1 | +--- |
| 2 | +title: CI/CD - Server token |
| 3 | +description: The Server Auth Token allows you to authenticate Zephyr plugins at the organization level without needing individual user credentials for every operation. It identifies the user performing actions via their email and enables secure access to Zephyr on behalf of your organization. |
| 4 | +--- |
| 5 | + |
| 6 | +import { Steps } from '@rspress/core/theme'; |
| 7 | + |
| 8 | +# CI/CD Integration using Server token |
| 9 | + |
| 10 | +The Server Auth Token allows you to authenticate Zephyr plugins at the organization level without needing individual user credentials for every operation. It identifies the user performing actions via their email and enables secure access to Zephyr on behalf of your organization. |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +- [Generate API Token](#generate-an-server-api-token) |
| 15 | +- [GitHub Actions Setup](#github-actions) |
| 16 | +- [GitLab CI/CD Setup](#gitlab-cicd) |
| 17 | +- [Troubleshooting](#troubleshooting) |
| 18 | + |
| 19 | +## Generate an Server API Token |
| 20 | + |
| 21 | +To use Zephyr Cloud in CI/CD pipelines, you'll need an API token for authentication: |
| 22 | + |
| 23 | +<Steps> |
| 24 | +### Organization Settings |
| 25 | + |
| 26 | +Go to your Organization Settings in Zephyr. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +### Server Tokens section |
| 31 | + |
| 32 | +Navigate to the Server Tokens section. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +### Click Generate Token Button |
| 37 | + |
| 38 | +Fill out the required information about the token you're about to generate |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +### Click Generate |
| 43 | + |
| 44 | +Copy the token for usage where you need to use it |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +</Steps> |
| 49 | + |
| 50 | +## GitHub Actions |
| 51 | + |
| 52 | +Zephyr requires an authenticated user to publish updates. Configure your GitHub Actions pipeline to build and deploy with Zephyr by adding a token to your repository secrets. |
| 53 | + |
| 54 | +### Adding the GitHub Secret |
| 55 | + |
| 56 | +1. Create a token on your organization settings page |
| 57 | +2. Add it as a repository secret in GitHub |
| 58 | +3. The secret must be assigned to the `ZE_SERVER_TOKEN` environment variable |
| 59 | +4. Set user email |
| 60 | + |
| 61 | +```yml title="pull_request.yml" |
| 62 | +env: |
| 63 | + ZE_SERVER_TOKEN: ${{ secrets.ZEPHYR_AUTH_TOKEN }} |
| 64 | + ZE_USER_EMAIL: <User Email> |
| 65 | +``` |
| 66 | +
|
| 67 | +### Authentication Behavior |
| 68 | +
|
| 69 | +When the Zephyr plugin detects the `ZE_SERVER_TOKEN` environment variable, it will automatically authenticate with the Zephyr API, bypassing the usual login step. |
| 70 | +The Zephyr needs a user email to identify who is performing builds. You can provide it in one of two ways: |
| 71 | + |
| 72 | +- Automatically from Git config |
| 73 | +- Manually via environment variable `ZE_USER_EMAIL` |
| 74 | + |
| 75 | +You'll see this confirmation in the console: |
| 76 | + |
| 77 | +```shell |
| 78 | + ZEPHYR Token found in environment. Using secret token for authentication. |
| 79 | +``` |
| 80 | + |
| 81 | +## GitLab CI/CD |
| 82 | + |
| 83 | +Configure your GitLab Runner pipeline to build and deploy with Zephyr by adding a token to the CI/CD variables. |
| 84 | + |
| 85 | +### Adding the GitLab CI/CD Variable |
| 86 | + |
| 87 | +1. Create a full access token on your [Organization Server tokens page](#server-tokens-section) page |
| 88 | +2. Add it as a CI/CD variable in your GitLab project: |
| 89 | + |
| 90 | +**Steps to add the token:** |
| 91 | + |
| 92 | +1. Navigate to your GitLab project |
| 93 | +2. Go to **Settings** → **CI/CD** |
| 94 | +3. Expand the **Variables** section |
| 95 | +4. Click **Add variable** |
| 96 | +5. Configure the variable: |
| 97 | + - **Key**: `ZE_SERVER_TOKEN` |
| 98 | + - **Key**: `ZE_USER_EMAIL` |
| 99 | + - **Value**: Your Zephyr API token |
| 100 | + - **Type**: Variable |
| 101 | + - **Environment scope**: All (or specify specific environments) |
| 102 | + - **Protect variable**: ✅ Check if you want to use it only in protected branches |
| 103 | + - **Mask variable**: ✅ Check to hide the value in job logs |
| 104 | + |
| 105 | +### Using the Token in GitLab CI/CD |
| 106 | + |
| 107 | +In your `.gitlab-ci.yml` file, the token will be automatically available as an environment variable: |
| 108 | + |
| 109 | +```yml title=".gitlab-ci.yml" |
| 110 | +build: |
| 111 | + stage: build |
| 112 | + script: |
| 113 | + - npm install |
| 114 | + - npm run build |
| 115 | + variables: |
| 116 | + ZE_SERVER_TOKEN: $ZE_SERVER_TOKEN |
| 117 | + ZE_USER_EMAIL: $ZE_USER_EMAIL |
| 118 | +``` |
| 119 | + |
| 120 | +For more explicit control, you can also reference it directly: |
| 121 | + |
| 122 | +```yml title=".gitlab-ci.yml" |
| 123 | +deploy: |
| 124 | + stage: deploy |
| 125 | + script: |
| 126 | + - npm install |
| 127 | + - npm run build |
| 128 | + environment: |
| 129 | + name: production |
| 130 | + variables: |
| 131 | + ZE_SERVER_TOKEN: $ZE_SERVER_TOKEN |
| 132 | + ZE_USER_EMAIL: $ZE_USER_EMAIL |
| 133 | +``` |
| 134 | + |
| 135 | +### Authentication Behavior |
| 136 | + |
| 137 | +When the Zephyr plugin detects the `ZE_SERVER_TOKEN` environment variable, it will automatically authenticate with the Zephyr API, bypassing the usual login step. |
| 138 | + |
| 139 | +You'll see this confirmation in the console: |
| 140 | + |
| 141 | +```shell |
| 142 | + ZEPHYR Token found in environment. Using secret token for authentication |
| 143 | +``` |
| 144 | + |
| 145 | +### Complete Pipeline Example |
| 146 | + |
| 147 | +Here's a full GitLab CI/CD pipeline configured for Zephyr deployment: |
| 148 | + |
| 149 | +```yml title=".gitlab-ci.yml" |
| 150 | +stages: |
| 151 | + - install |
| 152 | + - build |
| 153 | + - deploy |
| 154 | +
|
| 155 | +variables: |
| 156 | + npm_config_cache: '$CI_PROJECT_DIR/.npm' |
| 157 | +
|
| 158 | +cache: |
| 159 | + key: ${CI_COMMIT_REF_SLUG} |
| 160 | + paths: |
| 161 | + - .npm/ |
| 162 | + - node_modules/ |
| 163 | +
|
| 164 | +install: |
| 165 | + stage: install |
| 166 | + script: |
| 167 | + - npm ci --cache .npm --prefer-offline |
| 168 | + artifacts: |
| 169 | + paths: |
| 170 | + - node_modules/ |
| 171 | + expire_in: 1 hour |
| 172 | +
|
| 173 | +build: |
| 174 | + stage: build |
| 175 | + script: |
| 176 | + - npm run build |
| 177 | + artifacts: |
| 178 | + paths: |
| 179 | + - dist/ |
| 180 | + expire_in: 1 day |
| 181 | + variables: |
| 182 | + ZE_SERVER_TOKEN: $ZE_SERVER_TOKEN |
| 183 | + ZE_USER_EMAIL: $ZE_USER_EMAIL |
| 184 | +
|
| 185 | +deploy: |
| 186 | + stage: deploy |
| 187 | + script: |
| 188 | + - npm run deploy |
| 189 | + only: |
| 190 | + - main |
| 191 | + environment: |
| 192 | + name: production |
| 193 | + variables: |
| 194 | + ZE_SERVER_TOKEN: $ZE_SERVER_TOKEN |
| 195 | + ZE_USER_EMAIL: $ZE_USER_EMAIL |
| 196 | +``` |
| 197 | + |
| 198 | +## Security Notes |
| 199 | + |
| 200 | +- Do not share server tokens publicly. |
| 201 | +- Rotate tokens regularly and revoke any that may be compromised. |
| 202 | +- Remember: server tokens provide organization-level access, so they are sensitive credentials. |
| 203 | + |
| 204 | +## Troubleshooting |
| 205 | + |
| 206 | +### Authentication Issues |
| 207 | + |
| 208 | +**Token not found error:** |
| 209 | + |
| 210 | +- Verify the variables names are exactly `ZE_SERVER_TOKEN` and `ZE_USER_EMAIL` |
| 211 | +- Ensure the variables are available in the environment where your job runs |
| 212 | +- Check that the token hasn't expired |
| 213 | + |
| 214 | +### GitLab-Specific Issues |
| 215 | + |
| 216 | +**Protected variables:** |
| 217 | + |
| 218 | +- If using protected variables, ensure your pipeline runs on a protected branch or tag |
| 219 | + |
| 220 | +**Masked variables:** |
| 221 | + |
| 222 | +- Masked variables won't appear in job logs (recommended for security) |
| 223 | +- Temporarily unmask if you need to troubleshoot, then re-mask for production |
| 224 | + |
| 225 | +**Variable scope:** |
| 226 | + |
| 227 | +- Check that the variable scope matches your pipeline's environment requirements |
0 commit comments