Reads:38546Replies:0
Use Alibaba Cloud container service Jenkins to implement continuous integration (supplement)
A previous article titled Use Alibaba Cloud container service Jenkins to implement continuous integration & build Docker image detailed how to quickly create Jenkins applications through the Alibaba Cloud container service platform and implement continuous integration (CI) and build Docker images with the help of GitHub. In this article, we will use the Alibaba Cloud container service to establish GitLab as the code management library, and use the Jenkins plug-in aliyun-container-service-deploy to deploy applications. Two release policies, namely blue-green release and standard release, are supported.
1. Deploy Jenkins and slave node 1.1 One-click deployment using orchestration templates The example templates of Alibaba Cloud container service have built-in orchestration templates of Jenkins master and slave nodes in multiple languages. You can directly select a template for deployment. 1.2 Configure the slave node After the Jenkins application and Slave node are created, we need to add the just-created slave node in the Jenkins application so that the slave node can be used by Jenkins for executing projects. Open the Jenkins application and enter the system settings interface. Select Manage Nodes to create a new node. You should configure a tag, the slave node URL and access password for the node. When filling in the Credentials, you need to provide the Jenkins slave node SSH user name and password. The default user name and password are jenkins/jenkins. 2. Deploy GitLab 2.1 One-click deployment using orchestration templates The example templates of Alibaba Cloud container service provide GitLab orchestration templates with separated databases and applications. You can directly select a template for deployment. 2.2 Configure the host After the application is created successfully, configure the routing address to the host of the GitLab application. Find the just-created GitLab application in the application list, select to change the configuration and change the GITLAB_HOST environmental variable to the routing address. It is worth noting that you can only change the configuration after you update the application version. At this time, you can import the code in GitLab, or create a new code library. This article still uses the containerops code for demonstration. 3. Create a Jenkins project to implement simple CI processes For demonstration purposes, here we use a Jenkins project to implement the entire CI process. In a regular daily environment, you can add unit tests as needed as the precondition to enrich your CI process. Select to create a new freestyle project on the Jenkins application page. 3.1 Specify the node running the project Jenkins application projects run on the master node by default, that is, the installation environment of the application. Here we configure the project to run on the nodejs node we created above. 3.2 Configure source code management Fill in your code repository address in Repository URL. Add the account and password for pulling the code in the Credentials. 3.3 Configure and build triggers Select “Build when a change is pushed to GitLab”. In the “Advanced” configurations, you can control the triggering of corresponding code branches according to the name or regular expressions. 3.4 Add steps for creating and pushing images Add the building step of “Execute Shell” type to build and push images through shell scripts. 3.5 Add steps for deploying applications The Jenkins example templates of Alibaba Cloud container service have built-in application deployment plug-in Aliyun Container Service Deploy supporting selection of release policies, and you can add a building step of “Aliyun Container Service Deploy” type to deploy applications. Download the certificate zip package for deploying application clusters (decompressed to three files, key.pem, cert.pem and ca.pem) to obtain the cluster access address. Change the cluster access address to the https:// format and fill it into the MasterURL dialog box. Input the application name in the ApplicationName dialog box. Input the orchestration template location in the ComposeTemplate dialog box (relative path in the code). Select the desired release mode in the Publish Strategy dialog box. The standard release and blue-green release modes are supported. Add the certificate of the “Docker Host Certificate Authentication” type. Click Confirm, and our CI process has been created. At this time, by modifying the code of the jenkins-test branch in GitLab, we can see the changes to the application on the container service console. |
|