Skip to content

Commit e12ddb1

Browse files
Nstttzmzlois
andauthored
feat: add gitlab runner example with Zephyr (#126)
Co-authored-by: Lois <[email protected]>
1 parent c055912 commit e12ddb1

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

docs/how-to/gitlab-automations.mdx

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Building with GitLab Runner
2+
Zephyr requires an authenticated user in order to publish updates. In order to configure your GitLab Runner pipeline to build and deploy with Zephyr, you will need to add a token to the CI/CD variables.
3+
4+
## Adding the GitLab CI/CD Variable
5+
You will need to create a full access token on your [API token](https://app.zephyr-cloud.io/profile/settings/user-tokens) page. After creating this token, you will need to add it as a CI/CD variable in your GitLab project.
6+
7+
### Steps to add the token:
8+
1. Navigate to your GitLab project
9+
2. Go to **Settings****CI/CD**
10+
3. Expand the **Variables** section
11+
4. Click **Add variable**
12+
5. Set the following values:
13+
- **Key**: `ZE_SECRET_TOKEN`
14+
- **Value**: Your Zephyr API token
15+
- **Type**: Variable
16+
- **Environment scope**: All (or specify specific environments)
17+
- **Protect variable**: Check if you want to use it only in protected branches
18+
- **Mask variable**: Check to hide the value in job logs
19+
20+
## Using the token in GitLab CI/CD
21+
22+
In your `.gitlab-ci.yml` file, the token will be automatically available as an environment variable:
23+
24+
```yml title=.gitlab-ci.yml
25+
build:
26+
stage: build
27+
script:
28+
- npm install
29+
- npm run build
30+
variables:
31+
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN
32+
```
33+
34+
For more explicit control, you can also reference it directly:
35+
36+
```yml title=.gitlab-ci.yml
37+
deploy:
38+
stage: deploy
39+
script:
40+
- npm install
41+
- npm run build
42+
environment:
43+
name: production
44+
variables:
45+
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN
46+
```
47+
48+
## Plugin behavior when secret token presents
49+
When the Zephyr plugin is triggered on an environment that holds the `ZE_SECRET_TOKEN` environment variable, it will use this token to authenticate with the Zephyr API and bypass the usual log in step.
50+
51+
You will notice that with a log in the console, the plugin will print the following message:
52+
53+
```shell
54+
ZEPHYR Token found in environment. Using secret token for authentication
55+
```
56+
57+
## Example GitLab CI/CD Pipeline
58+
59+
Here's a complete example of a GitLab CI/CD pipeline using Zephyr:
60+
61+
```yml title=.gitlab-ci.yml
62+
stages:
63+
- install
64+
- build
65+
- deploy
66+
67+
variables:
68+
npm_config_cache: "$CI_PROJECT_DIR/.npm"
69+
70+
cache:
71+
key: ${CI_COMMIT_REF_SLUG}
72+
paths:
73+
- .npm/
74+
- node_modules/
75+
76+
install:
77+
stage: install
78+
script:
79+
- npm ci --cache .npm --prefer-offline
80+
artifacts:
81+
paths:
82+
- node_modules/
83+
expire_in: 1 hour
84+
85+
build:
86+
stage: build
87+
script:
88+
- npm run build
89+
artifacts:
90+
paths:
91+
- dist/
92+
expire_in: 1 day
93+
variables:
94+
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN
95+
96+
deploy:
97+
stage: deploy
98+
script:
99+
- npm run deploy
100+
only:
101+
- main
102+
environment:
103+
name: production
104+
variables:
105+
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN
106+
```
107+
108+
## Troubleshooting
109+
110+
### Token not found
111+
If you see an error about authentication failing, ensure:
112+
- The variable name is exactly `ZE_SECRET_TOKEN`
113+
- The variable is available in the environment where your job is running
114+
- The token has not expired
115+
116+
### Protected variables
117+
If using protected variables, ensure your pipeline is running on a protected branch or tag.
118+
119+
### Masked variables
120+
When a variable is masked, it won't appear in job logs. This is recommended for security but can make debugging harder. Temporarily unmask if you need to troubleshoot.

rspress.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ const sidebar: Sidebar = {
129129
text: "GitHub automations",
130130
link: "/how-to/github-automations",
131131
},
132+
{
133+
text: "Gitlab automations",
134+
link: "/how-to/gitlab-automations",
135+
},
132136
{
133137
text: "End-to-end Testing",
134138
link: "/how-to/end-to-end-testing",

0 commit comments

Comments
 (0)