基于Jenkins的openEuler Embedded CI部署

发布时间 2023-09-24 22:58:30作者: 终末之诗EndPoem_ZH

基于Jenkins的openEuler Embedded CI部署流程

下面主要以CentOS 7系统为例,写出全流程、可能遇到的问题及解决方案。

安装Jenkins

参考链接:https://www.jenkins.io/doc/book/installing/linux/

Debian/Ubuntu系统,执行下列指令安装Jenkins:

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

安装openjdk-17:

sudo apt install openjdk-17-jre
java -version
openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Debian-1deb11u1, mixed mode, sharing)

CentOS系统,执行下列指令安装Jenkins和openjdk-17:

sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
# Add required dependencies for the jenkins package
sudo yum install java-17-openjdk
sudo yum install jenkins
sudo systemctl daemon-reload

问题1:安装openjdk-17提示没有可用软件包

[root@localhost 下载]# sudo yum install java-17-openjdk
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirror.lzu.edu.cn
github_git-lfs/x86_64/signature                          |  833 B     00:00     
github_git-lfs/x86_64/signature                          | 1.8 kB     00:00 !!! 
github_git-lfs-source/signature                          |  833 B     00:00     
github_git-lfs-source/signature                          | 1.8 kB     00:00 !!! 
没有可用软件包 java-17-openjdk。
错误:无须任何处理

解决方法:
通过以下链接下载jdk 17:
https://www.oracle.com/java/technologies/downloads/#java17

问题2:无法将jenkins添加到docker群组中

[zh@localhost 下载]$ sudo gpasswd -a jenkins docker
gpasswd:docker 组不存在于 /etc/group 中

解决方法:
通过cat /etc/group | grep docker查看用户docker是否存在。测试时发现用户名为dockerroot,需执行sudo gpasswd -a jenkins dockerroot

注:安装docker后,需要启动docker:systemctl start docker,启动之后查看状态:systemctl status docker

新建Jenkins自动构建项目

sudo docker pull swr.cn-north-4.myhuaweicloud.com/openeuler-embedded/openeuler-ci-test:latest

参考链接:
openEuler在线文档 - 测试工程
https://openeuler.gitee.io/yocto-meta-openeuler/master/infrastructure/test/index.html

执行下列指令安装Python后:
[zh@localhost ~]$ sudo yum install python3 python3-pip docker
仍然可能提示未找到指令:
[zh@localhost ~]$ pip install oebuild
bash: pip: 未找到命令...

可通过如下指令安装pip2.7(对应python2):
[zh@localhost ~]$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
[zh@localhost ~]$ python get-pip.py

但遇到无法安装oebuild的问题(CentOS 7系统下):
[zh@localhost ~]$ pip install oebuild
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement oebuild (from versions: none)
ERROR: No matching distribution found for oebuild

同样无法通过二进制包的方式安装,可能对CentOS系统支持上有问题(Ubuntu可通过二进制包安装)
[zh@localhost oebuild-bin]$ pip install oebuild-0.0.1-py3-none-any.whl
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
ERROR: oebuild-0.0.1-py3-none-any.whl is not a supported wheel on this platform.
该问题已提Issue:
https://gitee.com/openeuler/oebuild/issues/I7XEID

openeuler.gitee.io并没有给出二进制仓的安装方式:
https://openeuler.gitee.io/yocto-meta-openeuler/master/getting_started/index.html#id3
gitee仓给出了安装方式:
https://gitee.com/openeuler/oebuild#https://gitee.com/alichinese/oebuild-bin

目前状况:无法在CentOS上正常安装oebuild,从而无法将用oebuild构建的指令添加到Jenkins中以自动构建。有待以后解决。
下面给出pipeline供参考:

参考pipeline

pipeline {
    agent { node "dockercloud" }      //这里的dockercloud即之前在 Docker Agent templates 中配置的Labels值
    environment {
        PATH = "/home/jenkins/.local/bin:${env.PATH}"
    }
    stages {
        stage('clone openeuler-ci') {
            steps {
                dir('/home/jenkins/agent'){
                    script {
                        if(fileExists('embedded-ci') == false) {
                            sh 'git clone https://gitee.com/openeuler/embedded-ci.git -v /home/jenkins/agent/embedded-ci --depth=1'
                        }
                    }
                }
            }
        }
        stage('run ci') {
            steps {
                dir('/home/jenkins/agent/embedded-ci'){
                    script{
                        withCredentials([usernamePassword(credentialsId: 'test_credentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
                            sh """python3 main.py ci \
                            -e /path \             //填写你想存储构建产物的路径
                            -i "101.1.10.101" \    //填写你想存储构建产物的机器的ip地址
                            -u $USERNAME \         //登录构建产物存储的机器时,使用的用户名
                            -w $PASSWORD \         //登录构建产物存储的机器时,使用的密码
                            -dm \                  //删除构建的tmp目录,该选项,默认为真,因为tmp目录使用较大空间,所以默认会删除tmp目录
-o openeuler \       //此参数当前无用,保留即可
-p yocto-meta-openeuler   //此参数当前无用,保留即可

                            """
                        }
                    }
                }
            }
        }
    }
}