Example GitLab Pipeline jobs for common Bit and Git CI/CD workflows.
You can leverage seamless integration of GitLab support through the Bit Docker image. Select from these available images:
-
Latest Stable:
bitsrc/stable:latest
-
Nightly:
bitsrc/nightly:latest
- Initialize Configuration File: Create
.gitlab-ci.yml
in your GitLab repository's root and with the code shown below. - Workspace Navigation: Move to the appropriate directory if your workspace isn't at the root of your Git repository. For instance, use
cd ws-dir
. - Script Initialization: Begin with
gitlab.bit.init
, as subsequent scripts will depend on it. - CI/CD Variables Setup: Define new CI/CD variables like:
GITLAB_TOKEN
: Project Access Token or Personal Access TokenBIT_CLOUD_ACCESS_TOKEN
You need BIT_CLOUD_ACCESS_TOKEN (docs).GIT_USER_NAME
GIT_USER_EMAIL
Ensure these variables are correctly configured within your GitLab CI pipeline.
Note: If you set the variables in GitLab project CI/CD variables, there's no need to explicitly define them inside your
.gitlab-ci.yml
file.
Task | Example |
---|---|
Initialize Bit | bit-init/.gitlab-ci.yml |
Bit Verify Components | verify/.gitlab-ci.yml |
Bit Tag and Export | tag-export/.gitlab-ci.yml |
Bit Merge Request Build | merge-request/.gitlab-ci.yml |
Bit Lane Cleanup | lane-cleanup/.gitlab-ci.yml |
Commit Bitmap | commit-bitmap/.gitlab-ci.yml |
Task | Example |
---|---|
Dependency Update | dependency-update/.gitlab-ci.yml |
Task | Example |
---|---|
Branch Lane | branch-lane/.gitlab-ci.yml |
gitlab.bit.init
Source: script details
The Bit Docker image comes with the latest Bit version pre-installed. Still, the gitlab.bit.init
script provides:
- Verification and possible installation of the relevant version as specified in the
engine
block of yourworkspace.jsonc
. - Initialization of default
org
andscope
variables for further tasks. - Execution of the
bit install
command inside the workspace.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
build-job:
stage: build
script:
- |
cd my-workspace-dir
gitlab.bit.init
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
gitlab.bit.verify
Source: script details
--skip-build
: This parameter, likegitlab.bit.verify --skip-build
, prevents thebit build
command execution.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
build-job:
stage: build
script:
- |
cd my-workspace-dir
gitlab.bit.init
gitlab.bit.verify
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
gitlab.bit.commit-bitmap --skip-ci
Source: script details
--skip-push
: Avoids pushing changes; useful for tests.--skip-ci
: Prevents re-triggering CI on code push, avoiding potential loops.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
build-job:
stage: build
script:
- |
cd my-workspace-dir
gitlab.bit.init
gitlab.bit.commit-bitmap --skip-ci
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
gitlab.bit.merge-request
Source: script details
Execute this script when a Merge Request is created. It verifies the components and create a lane in bit.cloud for previewing and testing components.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
merge-request-job:
stage: build
script:
- |
cd my-workspace-dir
gitlab.bit.init
gitlab.bit.merge-request
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
gitlab.bit.lane-cleanup
Source: script details
Execute this script when code is pushed to the main branch. It will detect whether the push is a result of a merge request merge event and will then proceed to clean up the lane.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
merge-request-closed-job:
stage: build
script:
- |
cd my-workspace-dir
gitlab.bit.init
gitlab.bit.lane-cleanup
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
gitlab.bit.tag-export
Source: script details
Tag component versions using labels on Merge Requests or within Merge Request/Commit titles. Use version keywords major
, minor
, patch
, and pre-release
.
Note: If a Merge Request is merged, track it via its
merge commit
in the target branch. For the action to detect the version keyword, themerge commit
should be the recent one in the commit history.
You can persist soft tagged components by adding --persist
flag.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
release-components-job:
stage: build
script:
- |
cd my-workspace-dir
gitlab.bit.init
gitlab.bit.tag-export
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
gitlab.bit.branch-lane
Source: script details
Execute this script when a new branch is created in Git. It will create a lane in bit.cloud for each new Branch and keep the lane in sync with the components modified in Git.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
build-job:
stage: build
script:
- |
cd test-ws
gitlab.bit.init
gitlab.bit.branch-lane
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
gitlab.bit.dependency-update --allow "envs, workspace-components"
Source: script details
Run this script as a scheduled pipeline, which will create a merge request to the specified branch with the updated dependencies.
--allow
: Allow different types of dependencies. Optionsall
,external-dependencies
,workspace-components
,envs
. You can also use a combination of one or two values, e.g.gitlab.bit.dependency-update --allow "external-dependencies, workspace-components"
. Defaultall
.--branch
: Branch to check for dependency updates. Defaultmain
.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
check-updates:
stage: build
script:
- |
cd test-ws
gitlab.bit.init
gitlab.bit.dependency-update --allow "all" --branch "main"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
To contribute, make updates to scripts starting with gitlab.bit.
in the Bit Docker Image Repository.
To create zip files use the below commands.
chmod +x zip-files.sh
bash ./zip-files.sh