Uploading Software Packages with Maven
When to Use
CodeArts Build allows you to configure build scripts using YAML files. You can use YAML syntax to compile the build environment, parameters, commands, and steps into a build.yml file, which can be stored in a code repository with the built code. The system uses the build.yml file as the build script to execute the build task, making the build process traceable, recoverable, secure, and reliable. The build with Maven is used as an example in this section.
Prerequisites
A project is available. If no project is available, create one.
Creating a Code Repository
- Log in to the CodeArts homepage using the Huawei Cloud account.
- Click the name of the project to create a repository for it.
- In the navigation pane, choose Figure 1. , as shown in
- Click New Repository.
- Set parameters based on Table 1 and click OK.
Table 1 Creating a code repository Parameter
Description
Repository Name
Customize the name for the code repository, for example, maven_yml_build.
- The name starts with a digit, letter, or underscore (_).
- The value can contain periods (.) and hyphens (-).
- The value cannot end with .git, .atom, or a period (.).
Description
Describe the code repository.
.gitignore Programming Language
Select .gitignore based on the programming language, for example, Java.
Permissions
Select all.
- Allow project members to access the repository: A project manager is automatically set as the repository administrator, and a developer is set as a common repository member. When the two roles are added to the project, they will be automatically synchronized to existing repositories.
- Generate README: You can edit the README file to record information such as the project architecture and compilation purpose, which is similar to a comment on the entire repository.
- Automatically create Check task (free of charge): After the repository is created, you can view the code check task of the repository in the check task list.
Visibility
Set this parameter to Private.
- Private: Only repository members can access and commit code.
- Public: The repository is open and read-only to all guests, but is not displayed in their repository list or search results. You can select an open-source license as the remarks.
Creating a build.yml File
- In the navigation pane, choose .
- Click the name of the code repository you created (see Creating a Code Repository).
- Choose Figure 2. , as shown in
- Set parameters based on Table 2 and click OK.
- Click the name of the directory created in Step 4.
- Choose Figure 3. , as shown in
- Name the file build.yml and copy the following code to the file:
# This YAML is the default template and can be modified based on this --- version: 2.0 steps: BUILD: - maven: image: cloudbuild@maven3.5.3-jdk8-open # You can customize the image path. inputs: settings: public_repos: - https://mirrors.huawei.com/maven cache: true # Indicates whether to enable the cache. command: mvn package -Dmaven.test.failure.ignore=true -U -e -X -B - upload_artifact: inputs: path: "**/target/*.?ar" - build_image: inputs: organization: codeci_gray # Organization name image_name: maven_demo # Image name image_tag: 1.0 # Image tag dockerfile_path: ./Dockerfile
- Click OK.
Creating a Java File
- Create a directory named src/main/java by referring to Step 4.
- Create the HelloWorld.java file in the src/main/java directory by referring to Step 6 and Step 7. The code in the file is as follows:
/** * Hello world * */ public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
- Click OK.
Creating a Dockerfile
- Create a file named Dockerfile in the root directory by referring to Step 6 and Step 7. The code in the file is as follows:
FROM swr.cn-north-5.myhuaweicloud.com/codeci/special_base_image:centos7-base-1.0.2-in MAINTAINER <devcloud@demo.com> USER root RUN mkdir /demo COPY ./target/server-1.0.jar /demo/app.jar
server-1.0.jar combines the values of artifactId, packaging, and version in the pom.xml file.
- Click OK.
Creating a pom.xml File
- Create a file named pom.xml in the root directory by referring to Step 6 and Step 7. The code in the file is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.huawei.demo</groupId> <artifactId>server</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>server</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> <manifestEntries> <Main-Class> HelloWorld </Main-Class> </manifestEntries> </archive> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
- Click OK.
Creating a Build Task
- In the navigation pane, choose Figure 4. , as shown in
- Click Create Task.
- Set the parameters based on the Table 3, as shown in Figure 5.
Table 3 Basic information Parameter
Description
Task Name
Enter a custom task name, for example, maven_yml_build.
Code Source
Select Repo.
Source Code Repository
Select the code repository you created (see Creating a Code Repository).
Branch
Select the branch created when you create the repository in Creating a Code Repository. If no branch is available, select the default master.
Description
Describe the build task.
- Click Next.
- Select Blank Template and click Next.
- Click the Code tab to view the imported build script, as shown in Figure 6.
- Click Create and Run in the upper right corner.
Viewing and Verifying the Build Result
- Verifying the uploaded the software package
- In the navigation pane, choose .
- Go to the release repos to view the released software package. The name of the software package is the same as the task name you use when Creating a Build Task, as shown in Figure 7.
- Viewing the pushed image
- Go to the SWR console.
- In the navigation pane, choose My Images. In the organization filter box, search for the organization name you enter in the code when you create a build.yml file, for example, codeci_gray.
- In the filtering results, click the image name you enter in the code when you create a build.yml file, for example, maven_demo, as shown in Figure 8.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot