OpenHarmony开发者论坛

标题: jenkins_script脚本介绍 [打印本页]

作者: 润开鸿_闻飞    时间: 6 天前
标题: jenkins_script脚本介绍
[md][itopen组织](https://gitee.com/itopen)
1、提供OpenHarmony优雅实用的小工具
2、手把手适配riscv + qemu + linux的三方库移植
3、未来计划riscv + qemu + ohos的三方库移植 + 小程序开发
4、一切拥抱开源,拥抱国产化

## 一、脚本简介

脚本下载链接:[itopen: jenkins_script](https://gitee.com/itopen/jenkins_script)

该脚本作用是基于jenkins智能搭建OpenHarmony产品测试任务而准备的。

通常我们使用jenkins搭建自动化测试任务时都是编写一个测试运行脚本,然后jenkins创建任务,在任务的Build Steps里调用编写好的脚本,如果是一个产品还好,但是如果有10多个,20个多个产品,那么维护的脚本就有10多20多个,维护成本则成倍增加,而针对都是同一类型的OpenHarmony产品,其代码下载、编译、构建其实都是很类似的。

因此这里我们可以将所有的任务归类统一化调用,通过jenkins的JOB_NAME来区分任务,同时在product.list中将对应任务产品的相关参数配置齐全即可,而任务的创建只需要复制配置好的任务即可,连调用脚本都不用修改,都是统一的build.sh.

## 二、脚本介绍

### 2.1 使用前准备

- **ssh配置**

  必须提前将本地root账号的ssh的public-key内容添加到代码的gitlab/gerrit/gitee账号下,具体操作不介绍,百度上很多
- **git配置**

  执行如下命令,配置好本地git

  ```shell
  git config --global user.name "yourname"
  git config --global user.email "your-email-address"
  git config --global core.editor vim
  git config --global credential.helper store
  git config --global http.sslverify false
  ```

  本地下载gitlab任意一个仓,如果没有自行创建一个仓,如果Ubunut是首次访问该gitlab会要求输入账号和密码

  ```shell
  test@pc220522:~/test$ git clone https://isrc.iscas.ac.cn/gitlab/ ... lab_code_update.git
  Cloning into 'gitlab_code_update'...
  Username for 'https://isrc.iscas.ac.cn': wen_fei # 输入gitlab的用户名
  Password for 'https://wen_fei@isrc.iscas.ac.cn': # 输入gitlab的密码
  remote: Enumerating objects: 65, done.
  remote: Counting objects: 100% (65/65), done.
  remote: Compressing objects: 100% (64/64), done.
  remote: Total 65 (delta 32), reused 0 (delta 0), pack-reused 0
  Unpacking objects: 100% (65/65), done.
  ```

  结束后检查 `~/.git-credentials`中是否出现了如下的一条记录,如果没有可以手动创建该文件并手动添加进去

  ```shell
  https://user_name:passwd@ip

  # 样例
  https://zhang_san:123456aA@gitee.com
  https://zhang_san:123456aA@192.169.1.100
  ```
- **repo首次下载配置**

  本地root账号不得是首次使用repo下载代码,否则先使用repo配置一下环境,因为有一个测试颜色输出,直接输入y回车即可

  ```shell
  test@pc220522:~/test$ mkdir -p ~/test && cd ~/test
  test@pc220522:~/test$ repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify

  Your identity is: wenfei <wenfei@163.com>
  If you want to change this, please re-run 'repo init' with --config-name

  Testing colorized output (for 'repo diff', 'repo status'):
    black    red      green    yellow   blue     magenta   cyan     white
    bold     dim      ul       reverse
  Enable color display in this user account (y/N)? y # 输入y然后回车

  repo has been initialized in /home/test/test
  ```

### 2.2 product.list参数介绍

| 参数名               | 示例                                       | 说明                                                                                        |
| -------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------- |
| id                   | 1.1                                        | 只是序号记录,任务中无意义                                                                  |
| job_name             | openharmony-v4.0-build                     | 和jenkins创建的任务名称必须一致                                                             |
| path_name            | dayu800-v3.2.2-release                     | 代码下载的目录名,前面有统一的下载目录为DAILY_PATH: /jenkins/ohos-daily/$(date +"%Y_%m_%d") |
| level                | L2                                         | 鸿蒙系统的等级,值为:L0/L1/L2                                                              |
| image_name           | openharmony-v4.0-release                   | 后面将打包的镜像重新命名                                                                    |
| manifest_url         | https://gitee.com/openharmony/manifest.git | repo下载代码的url,下载过OpenHarmony代码的都懂                                              |
| manifest_branch      | OpenHarmony-v4.0-Release                   | repo下载代码的branch                                                                        |
| manifest_xml         | default.xml                                | repo下载代码的xml                                                                           |
| prebuild_src_name    | openharmony_prebuilts_v4.0                 | ./build/prebuilts_download.sh预下载保存的文件名                                             |
| prebuild_dst_name    | openharmony_prebuilts                      | 该分支预下载在上级目录的目录名                                                              |
| board_name           | dayu800                                    | 编译时候的product_name                                                                      |
| build_args1          | -                                          | 编译中--gn-args的参数内容,没有就填写-,本脚本支持5个参数                                   |
| build_args2          | -                                          | 编译中--gn-args的参数内容,没有就填写-                                                      |
| build_args3          | -                                          | 编译中--gn-args的参数内容,没有就填写-                                                      |
| build_args4          | -                                          | 编译中--gn-args的参数内容,没有就填写-                                                      |
| build_args5          | -                                          | 编译中--gn-args的参数内容,没有就填写-                                                      |
| bat_script_name      | dayu800_v4.0_flash.bat                     | windows烧录镜像的脚本,没有填写-                                                            |
| is_tar_libunstripped | yes                                        | 是否需要打包没有trip的库,方便调试,选项:yes/no                                            |
| is_tar_sdk           | yes                                        | 是否需要打包sdk,选项:yes/no                                                               |

### 2.3 jenkins创建任务

Build Steps选择执行shell,然后添加以下命令即可

```
bash /jenkins/task/build.sh
```
[/md]




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5