Pipeline
GitCode Pipeline is a Continuous Integration and Continuous Delivery (CI/CD) platform designed to help developers automate the build, test, and deployment processes. You can create workflows to automate management from code commits to production environment deployments.
This document will introduce you to the core components of the GitCode Pipeline, creation process, and how to view pipeline execution results, helping you get started quickly and make full use of this tool.
Core Components
Workflow
A workflow is a configurable automated process used to execute one or more jobs. It is defined by a YAML file in the project, typically located under the .gitcode/workflows
directory. Workflows can be triggered by specific events such as code pushes, pull requests, or issue creations, or they can be manually triggered or scheduled to run.
A project can contain multiple workflows, each performing different tasks. For example, you can have a workflow to build and test pull requests, another workflow to deploy applications whenever a release is created, and yet another workflow to add labels when new issues are opened.
Events
Events are specific activities that trigger the execution of a workflow. Common events include:
- Code Push: Triggered when code is pushed to a specific branch.
- Pull Request: Triggered when a pull request is created or updated.
- Issue Creation: Triggered when a new issue is created.
- Manual Trigger: Manually start a workflow via the GitCode interface or API.
- Scheduled Trigger: Automatically execute the workflow according to a predefined schedule.
Jobs
Jobs are execution units within a workflow, containing a series of steps executed in sequence. Each job runs on an independent runner (Runner). Steps can be shell scripts or custom actions (Actions), and data can be shared between steps. Dependencies can be set between jobs to ensure certain jobs only run after others have completed.
For example, you can configure the following jobs:
- Build Job: Compile code and generate executable files.
- Test Job: Run unit tests and integration tests.
- Package Job: Package the build results into deployable images or files.
Actions
Actions are reusable extensions available on the GitCode platform for executing complex but common tasks. By using actions, you can reduce repetitive code in your workflow files and simplify process configurations. GitCode provides several built-in actions, such as:
- checkout-action: Pull code from GitCode.
- setup-node: Configure Node.js environment.
- setup-java: Configure Java environment.
- setup-python: Configure Python environment.
- setup-go: Configure Go environment.
You can write your own actions or find suitable ones in the GitCode plugin marketplace.
Runners
Runners are servers that execute workflows. Each time a workflow is triggered, GitCode assigns a brand new virtual machine runner for each job. Each runner can run one job at a time. GitCode provides Euler (EulerOS) runners by default, ensuring that each job runs in an isolated and clean environment.
Creating a Pipeline
Through YAML
In your GitCode project, create a .gitcode/workflows
directory to store workflow files. Under this directory, create a new YAML file, such as gitcode-sample.yml
, and add the following content:
name: gitcode-sample
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: euleros-2.10.1
steps:
- uses: checkout-action@0.0.1
- name: Use Node.js
uses: setup-node@0.0.1
with:
node-version: '20.10.0'
- run: cd repo_workspace && npm ci
- run: cd repo_workspace && npm run build --if-present
- run: cd repo_workspace && npm test
Commit and push these changes to your GitCode project.
Through Interface
-
In the project's "Pipeline" tab, click the "New Pipeline" button.
-
Select a template. GitCode provides various predefined workflow templates, and you can choose a suitable template based on your project requirements.
Executing the Pipeline
After configuration, click the "Execute" button to start the pipeline. GitCode will automatically execute tasks such as builds and tests based on the definitions in the workflow file.