We have created a pipeline based on the Jenkinsfile in last tutorial, actually it requires the users be familiar with Jenkinsfile syntax. In this tutorial we will demonstrate how to create a pipeline in a friendly UI, and there is no need to write Jenkinsfile.
About 30 minutes.
The following flow chart briefly illustrates the process of entire 6 stages of this pipeline.
- Instructions
- Stage 1 - Checkout SCM: Pull source code from GitHub.
- Stage 2 - Get dependencies: Install all of the dependencies using yarn.
- Stage 3 - Unit test: If the unit test passes, then it will continue to execute the following tasks.
- Stage 4 - Build: Execute the build command to generate the static Web.
- Stage 5 - Build and push snapshot image: Build an image based on the branch selected in the behavioral strategy, and push the image with tag
SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
to DockerHub.- Stage 6 - Deploy to Dev: Deploy the master branch to the Dev environment, which needs to be reviewed.
For the convenience of demonstration, this document still uses the GitHub repository devops-docs-sample as an example.
In this step, we'll create a pipeline to deploy the Docs web service to Dev environment, based on the yaml file.
Note: If you have already created the project
kubesphere-docs-dev
in the last tutorial, you can ignore and skip the following 3 steps.
project-regular
, click into Workbench, choose Projects → Create and select Create a resource project.kubesphere-docs-dev
, others can be customized by yourself. Project kubesphere-docs-dev
has been created successfully which represents the Dev environment.
Enter into DevOps Project devops-demo
, we are going to create 2 credentials totally.
Choose Credentials and click Create Credentials.
Fill in the basic information for DockerHub Credential.
Click OK when you're done.
Same as above, click Create Credentials to create a credential for kubeconfig
, name Credential ID as demo-kubeconfig, then click OK when you're done.
At this point, we have created 2 credentials totally.
jenkinsfile-out-of-SCM
, then click Next.Parameter Category | Name | Default Value | Description |
---|---|---|---|
String | DOCKERHUB_NAMESPACE | enter your DockerHub account (It can also be the organization name) |
DockerHub Namespace |
String | APP_NAME | enter devops-docs-sample |
Application Name |
H H * * *
into Schedule, which means it will trigger build once a day (no specific time limit). Click OK when you're done.Note: Timing build is similar to Linux Cron, for syntax details you can see Jenkins Documentation.
This pipeline includes 6 stages totally, we are going to instruct what steps and tasks within each stage. Firstly we are going to set Type and label within Agent.
node
.nodejs
.Add step
, then choose git
and enter the URL of sample repository: https://github.com/kubesphere/devops-docs-sample.git
, click OK to finish the first stage.From Stage 2 to Stage 5, actually we need to point these 4 stages into nodejs containers to run the shell scripts in sequence.
+
button to add the second stage which is used to get dependencies, thus we can enter get dependencies as its name. Then click Add Step
.nodejs
, then click OK.Add nesting steps
under the nodejs container, and choose shell
which is used to execute shell command, then enter yarn
into the popup command window.
+
to create the third stage, name it as unit test
.Click Add step
in stage unit test
and choose container
, name it as nodejs
then click OK
.
Click Add nesting stage
and choose shell
, input yarn test
for unit test in popup window. Click OK
when you're done.
+
to create the forth stage which is used to build a web in this container, name it build
.Click Add step
in stage build
and choose container
, name it nodejs
then click OK
.
Click Add nesting steps
and select shell
, then you can input yarn build
, then click OK
.
+
button to add the fifth stage, name as build and push snapshot image
. This stage is used to build snapshot image and push to DockerHub.Click Add Step and choose container
, then name it nodejs
and click OK
to save it.
Choose Add nesting steps
and select shell
, enter a line of docker command as following:
docker build -t docker.io/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-CRON-BUILD-$BUILD_NUMBER .
Add nesting steps
at the right zone, then choose withCredentials
and enter following values into a popup window, click OK to save it when you're done.dockerhub-id
that we created before.DOCKER_PASSWORD
.DOCKER_USERNAME
.Note: Because of the security of user information, account information is not allowed to appear in the script with clear text, but in the form of variables.
withCredentials
, both of them are used to run shell scripts. Click Add nesting steps
within withCredentials
, then enter following scripts:echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
Add nesting steps
again within withCredentials
, and the second docker command as following:docker push docker.io/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-CRON-BUILD-$BUILD_NUMBER
At this point, we have created 5 stages totally. Next we are going to add a stage to deploy to KubeSphere.
Click +
button to add a new stage also the last stage as well.
Click Add Step
and choose input
at right sidebar which is used to manual check. Reference the following information:
id: enter deploy-to-dev
Message: enter Deploy to dev?
Submitter: you can choose and enter project-admin
to review and approve this pipeline.
Click Add Step
in current stage and choose kubernetesDeploy
, then reference below to fill in the blanks within the popup window:
Kubeconfig: select demo-kubeconfig
that we created before.
Config Files: enter deploy/no-branch-dev/**
.
Click OK to save it.
At this point, we have create 6 stages totally, then click Confirm and choose Save at the right bottom of this page.
Activity
list to inspect the task status of each stage.Log out KubeSphere, and sigh in with project-admin
, then enter into Jenkinsfile-out-of-SCM
.
Once the pipeline runs to Deploy to dev
, it requires project-admin
to review and proceed to run. Click Proceed
in Deploy to dev
stage.
Once each stage of this pipeline run successfully, we can see the status showing Success
in this panel.
Thus the image with different tag will be pushed to DockerHub, also the deployment and service will be deployed to kubesphere-docs-dev
. See the table as following:
Environment | Accessing URL | Project | Deployment | Service |
---|---|---|---|---|
Dev | http://EIP:30860 (i.e. ${EIP}:${NODEPORT} ) |
kubesphere-docs-dev | ks-docs-sample-dev | ks-docs-sample-dev |
Accessing the Docs service of Dev and Production environment:
Dev Environment
Enter http://EIP:30860/
in your browser to preview the service.
At this point, we have successfully created a pipeline in friendly UI, it's recommeded you to follow with the next tutorial.