Quickly create a pipeline¶
This section will create a pipeline by compiling, building, and deploying, and will help you quickly create a pipeline through detailed step-by-step descriptions.
Prerequisites¶
- Need to create a workspace and a user, the user needs to join the workspace and give
workspace edit
role. Refer to Creating Workspaces, Users and Roles. - Create two credentials that can access the container registry and the cluster, named respectively:
registry
,kubeconfig
. For more information on creating credentials, please refer to Credential Management. - Prepare a GitHub repository, DockerHub repository.
Create Credentials¶
-
Create two credentials on the Credentials page:
- docker-credential: username and password for accessing the container registry.
- demo-dev-kubeconfig: used to access the Kubernetes cluster using this kubeconfig.
-
After the creation is complete, you can see the credential information on the
Certificate List
page.
Create a custom pipeline¶
-
Click
Create Pipeline
on the pipeline list page. -
In the pop-up dialog box, select Custom Create Pipeline and click OK.
-
Enter the
custom pipeline creation page
, and enter the pipeline namepipeline-demo
. -
Add three string parameters in
Build Parameters
, these parameters will be used in the image build command.- registry: container registry address. Example value:
release.daocloud.io
. - project: The name of the project in the container registry. Example value:
demo
. - name: The name of the image. Example value:
http-hello
.
- registry: container registry address. Example value:
-
After adding, click
OK
.
Edit pipeline¶
-
Click the name of a pipeline on the pipeline list page.
-
Click
Edit Pipeline
in the upper right corner, -
Click
Global Settings
in the upper right corner. -
Set the type to node and the label to go, click
OK
. -
Add stage - pull source code.
- Click on
Add Stage
in the canvas. In the stage settings on the right set the name: git clone. - Click
Add Step
, select git clone under the step type in the pop-up dialog box, and configure related parameters:- Repository URL: Enter the GitLab repository address.
- Branch: if not filled in, the default is the master branch.
- Credentials: If it belongs to a private registry, you need to provide a credential.
- Click on
-
Add stage - build and push the image.
-
Click on
Add Stage
in the canvas. Set the name in the stage settings on the right: build & push. -
In the step module, select to enable
specify container
, fill in the container name: go in the pop-up dialog box, and then clickOK
. -
Select to enable
Use Credentials
in the step module, fill in the relevant parameters in the pop-up dialog box, and then clickOK
.- Credentials: Select the created Docker hub credentials to allow users to access the container registry.
- Password variable: PASS
- Username variable: USER
-
Click
Add Step
to build the code, select shell under the step type in the pop-up dialog box, enter the following command in the command line, and then clickOK
. -
Click
Add Step
to build the Docker image according to the Dockerfile in the source code, select shell under the step type in the pop-up dialog box, enter the following command in the command line, and clickOK
. -
Click
Add Step
to log in to the container registry, select shell under the step type in the pop-up dialog box, enter the following command in the command line, and then clickOK
. -
Click
Add Step
to push the image to the container registry, select shell under the step type in the pop-up dialog box, enter the following command in the command line, and clickOK
.
-
-
Add stage - deploy to cluster
-
Click on
Add Stage
in the canvas. In the stage settings on the right set the name: deploy. -
In the step module, select to enable
specify container
, fill in the container name: go in the pop-up dialog box, and then clickOK
. -
Select to enable
Use Credentials
in the step module, fill in the relevant parameters in the pop-up dialog box, and then clickOK
.-
Credentials: Choose a credential of type kubeconfig.
-
kubeconfig variable: If you are using the kubectl apply deployment method, the variable value must be KUBECONFIG.
-
-
Click
Add Step
to perform the cluster deployment operation, select shell under the step type in the pop-up dialog box, enter the following command in the command line, and clickOK
.
-
Save and execute the pipeline pipeline¶
-
Click
Save and Execute
after completing the previous step. -
In the displayed dialog box, enter the sample parameters in step 2. Click
OK
to run the pipeline successfully.