-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add gitlab runner example with Zephyr #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Building with GitLab Runner | ||
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. | ||
|
||
## Adding the GitLab CI/CD Variable | ||
You will need to create a 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. | ||
|
||
### Steps to add the token: | ||
1. Navigate to your GitLab project | ||
2. Go to **Settings** → **CI/CD** | ||
3. Expand the **Variables** section | ||
4. Click **Add variable** | ||
5. Set the following values: | ||
- **Key**: `ZE_SECRET_TOKEN` | ||
- **Value**: Your Zephyr API token | ||
- **Type**: Variable | ||
- **Environment scope**: All (or specify specific environments) | ||
- **Protect variable**: Check if you want to use it only in protected branches | ||
- **Mask variable**: Check to hide the value in job logs | ||
|
||
## Using the token in GitLab CI/CD | ||
|
||
In your `.gitlab-ci.yml` file, the token will be automatically available as an environment variable: | ||
|
||
```yml title=.gitlab-ci.yml | ||
build: | ||
stage: build | ||
script: | ||
- npm install | ||
- npm run build | ||
variables: | ||
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN | ||
``` | ||
|
||
For more explicit control, you can also reference it directly: | ||
|
||
```yml title=.gitlab-ci.yml | ||
deploy: | ||
stage: deploy | ||
script: | ||
- npm install | ||
- npm run build | ||
environment: | ||
name: production | ||
variables: | ||
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN | ||
``` | ||
|
||
## Plugin behavior when secret token presents | ||
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. | ||
|
||
You will notice that with a log in the console, the plugin will print the following message: | ||
|
||
```shell | ||
ZEPHYR Token found in environment. Using secret token for authentication | ||
``` | ||
|
||
## Example GitLab CI/CD Pipeline | ||
|
||
Here's a complete example of a GitLab CI/CD pipeline using Zephyr: | ||
|
||
```yml title=.gitlab-ci.yml | ||
stages: | ||
- install | ||
- build | ||
- deploy | ||
|
||
variables: | ||
npm_config_cache: "$CI_PROJECT_DIR/.npm" | ||
|
||
cache: | ||
key: ${CI_COMMIT_REF_SLUG} | ||
paths: | ||
- .npm/ | ||
- node_modules/ | ||
|
||
install: | ||
stage: install | ||
script: | ||
- npm ci --cache .npm --prefer-offline | ||
artifacts: | ||
paths: | ||
- node_modules/ | ||
expire_in: 1 hour | ||
|
||
build: | ||
stage: build | ||
script: | ||
- npm run build | ||
artifacts: | ||
paths: | ||
- dist/ | ||
expire_in: 1 day | ||
variables: | ||
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN | ||
|
||
deploy: | ||
stage: deploy | ||
script: | ||
- npm run deploy | ||
only: | ||
- main | ||
environment: | ||
name: production | ||
variables: | ||
ZE_SECRET_TOKEN: $ZE_SECRET_TOKEN | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
### Token not found | ||
If you see an error about authentication failing, ensure: | ||
- The variable name is exactly `ZE_SECRET_TOKEN` | ||
- The variable is available in the environment where your job is running | ||
- The token has not expired | ||
|
||
### Protected variables | ||
If using protected variables, ensure your pipeline is running on a protected branch or tag. | ||
|
||
### Masked variables | ||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.