1 | # Using semantic-release with [GitLab CI](https://about.gitlab.com/features/gitlab-ci-cd)
|
2 |
|
3 | ## Environment variables
|
4 |
|
5 | The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured with [Protected variables](https://docs.gitlab.com/ce/ci/variables/README.html#protected-environment-variables).
|
6 |
|
7 | **Note**: Make sure to configure your release branch as [protected](https://docs.gitlab.com/ce/user/project/protected_branches.html) in order for the CI/CD build to access the protected variables.
|
8 |
|
9 | ## Node project configuration
|
10 |
|
11 | GitLab CI supports [Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html) allowing to test on multiple Node versions and publishing a release only when all test pass.
|
12 |
|
13 | **Note**: The publish pipeline must run a [Node >= 10.18 version](../support/FAQ.md#why-does-semantic-release-require-node-version--1018).
|
14 |
|
15 | ### `.gitlab-ci.yml` configuration for Node projects
|
16 |
|
17 | This example is a minimal configuration for **semantic-release** with a build running Node 10 and 12. See [GitLab CI - Configuration of your jobs with .gitlab-ci.yml](https://docs.gitlab.com/ee/ci/yaml/README.html) for additional configuration options.
|
18 |
|
19 | **Note**: The`semantic-release` execution command varies depending if you are using a [local](../usage/installation.md#local-installation) or [global](../usage/installation.md#global-installation) **semantic-release** installation.
|
20 |
|
21 | ```yaml
|
22 | # The release pipeline will run only if all jobs in the test pipeline are successful
|
23 | stages:
|
24 | - test
|
25 | - release
|
26 |
|
27 | before_script:
|
28 | - npm install
|
29 |
|
30 | node:10:
|
31 | image: node:10
|
32 | stage: test
|
33 | script:
|
34 | - npm test
|
35 |
|
36 | node:12:
|
37 | image: node:12
|
38 | stage: test
|
39 | script:
|
40 | - npm test
|
41 |
|
42 | publish:
|
43 | image: node:12
|
44 | stage: release
|
45 | script:
|
46 | - npx semantic-release
|
47 | ```
|
48 |
|
49 | ### `.gitlab-ci.yml` configuration for all projects
|
50 |
|
51 | This example is a minimal configuration for **semantic-release** with a build running Node 10 and 12. See [GitLab CI - Configuration of your jobs with .gitlab-ci.yml](https://docs.gitlab.com/ee/ci/yaml/README.html) for additional configuration options.
|
52 |
|
53 | **Note**: The`semantic-release` execution command varies depending if you are using a [local](../usage/installation.md#local-installation) or [global](../usage/installation.md#global-installation) **semantic-release** installation.
|
54 |
|
55 |
|
56 | ```yaml
|
57 | # The release pipeline will run only on the master branch a commit is triggered
|
58 | stages:
|
59 | - release
|
60 |
|
61 | release:
|
62 | image: node:10-buster-slim
|
63 | stage: release
|
64 | before_script:
|
65 | - apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
|
66 | - npm install -g semantic-release @semantic-release/gitlab
|
67 | script:
|
68 | - semantic-release
|
69 | only:
|
70 | - master
|
71 |
|
72 | release:
|
73 | image: node:12-buster-slim
|
74 | stage: release
|
75 | before_script:
|
76 | - apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
|
77 | - npm install -g semantic-release @semantic-release/gitlab
|
78 | script:
|
79 | - semantic-release
|
80 | only:
|
81 | - master
|
82 | ```
|
83 |
|
84 | ### `package.json` configuration
|
85 |
|
86 | A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation.
|
87 |
|
88 | ```json
|
89 | {
|
90 | "devDependencies": {
|
91 | "semantic-release": "^15.0.0"
|
92 | }
|
93 | }
|
94 | ```
|