【测试平台】打包 jenkins配置和jenkinsfile文件

背景:

当打包机环境配置完成后,需要挂到master的jenkins中,完成调度。

jenkins启动

命令行直接启动即可。

nohup java -jar /usr/local/opt/jenkins/libexec/jenkins.war --httpListenAddress=0.0.0.0 --httpPort=80 appending output to nohup.out

jenkins配置从节点

管理系统->节点列表->新增节点

端口号(需要和 IT 给开的端口号 配置一致,不一定是图中的端口号)和 java环境变量

配置完成后看连接日志

成功这个样子,有报错的话 根据报错修改配置选项

jenkins新建一个jenkins job

可以选择复制一个现有的工程项目名字进行修改

手工构建jenkins Job

JenkinsfIle文件

shell本质jenkins的流水线语法,具体语法可以自己查下。

前置混淆操作
后置混淆操作

FQA

1.挂节点机器报链接错误

原因:远程链接默认端口号为22,如果开的远程端口号不是22,是其他值,那就会报链接错误。需要需要设定端口

解决方案

2.挂节点机器报java环境变量错误

报错原因:因为节点机器配置的java环境变量不在/usr/local/java/bin/java路径上

解决方案:

Manage Jenkins > Manage Nodes and Clouds > Configure node > Advanced section under Launch Agents via ssh block > "update Java path in there"

[08/23/23 10:43:44] [SSH] Checking java version of /usr/local/java/bin/java
Couldn't figure out the Java version of /usr/local/java/bin/java /usr/local/java/bin/java
bash: /usr/local/java/bin/java: No such file or directory

java.io.IOException: Java not found on hudson.slaves.SlaveComputer@3dd3ad4b. Install Java 8 or Java 11 on the Agent.
        at hudson.plugins.sshslaves.JavaVersionChecker.resolveJava(JavaVersionChecker.java:83)
        at hudson.plugins.sshslaves.SSHLauncher.lambda$launch$0(SSHLauncher.java:453)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
[08/23/23 10:43:44] Launch failed - cleaning up connection
[08/23/23 10:43:44] [SSH] Connection closed.

3.挂节点机器提示权限错误

原因:/home/admin/.jenkins使用的是root权限创建的,所以admin账号没有相关权限

解决方案:

复制代码

[root@bogon admin]# chown -R admin:admin /home/admin/.jenkins

报错详情:

[08/23/23 10:49:28] [SSH] Starting sftp client.
[08/23/23 10:49:28] [SSH] Copying latest remoting.jar...
java.io.IOException: Could not copy remoting.jar into '/home/admin/.jenkins' on agent
        at hudson.plugins.sshslaves.SSHLauncher.copyAgentJar(SSHLauncher.java:733)
        at hudson.plugins.sshslaves.SSHLauncher.lambda$launch$0(SSHLauncher.java:456)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.io.IOException: Could not copy remoting.jar to '/home/admin/.jenkins/remoting.jar' on agent
        at hudson.plugins.sshslaves.SSHLauncher.copyAgentJar(SSHLauncher.java:725)
        ... 5 more
Caused by: com.trilead.ssh2.SFTPException: Permission denied (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation.)
        at com.trilead.ssh2.SFTPv3Client.openFile(SFTPv3Client.java:1201)
        at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1074)
        at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1055)
        at com.trilead.ssh2.jenkins.SFTPClient.writeToFile(SFTPClient.java:102)
        at hudson.plugins.sshslaves.SSHLauncher.copyAgentJar(SSHLauncher.java:718)
        ... 5 more
[08/23/23 10:49:28] Launch failed - cleaning up connection
[08/23/23 10:49:28] [SSH] Connection closed.

4.构建打包jenkins 报git 相关错误

原因:因为是使用root账号去安装git 和配置密钥的,所以admin账号无法拉取git

解决方案:使用admin账号进行配置git和密钥

Started by user admin
Obtained script/Jenkinsfiles/android-hertz/Jenkinsfile from git https://git.joyme.sg/joymeqa/odin.git
[Pipeline] Start of Pipeline
[Pipeline] node
Running on 10.61.153.59 in /home/admin/.jenkins/workspace/android-7hz[Pipeline] {
[Pipeline] VersionNumber
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (clean source)
[Pipeline] sh
+ git clean -df
+ git reset --hard
HEAD is now at ba42594 change by odin auto builder
+ git pull --rebase
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.[Pipeline] }[Pipeline] // stage[Pipeline] stage
[Pipeline] { (building)
Stage "building" skipped due to earlier failure(s)[Pipeline] }[Pipeline] // stage[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] sh
+ '[' nujoom_1.5.90_gp_rb '!=' master ']'
+ git clean -df
+ git reset --hard
HEAD is now at ba42594 change by odin auto builder
+ git checkout master
Already on 'master'
+ git branch -D nujoom_1.5.90_gp_rb
Deleted branch nujoom_1.5.90_gp_rb (was 78c6a5a).[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // withEnv[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineERROR: script returned exit code 1
Finished: FAILURE

5.构建时ssh 10.61.158.55 机器报错Host key verification failed

+ ssh building@10.61.158.55 mkdir -p /Users/building/odin-h5ai/android-charmchat-sockpuppet/CharmChat/charmchat_1.0.0_gp_rb/20230829.7
Host key verification failed.
Error when executing failure post condition:
hudson.AbortException: script returned exit code 255
        at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.handleExit(DurableTaskStep.java:664)
        at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.check(DurableTaskStep.java:610)
        at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.run(DurableTaskStep.java:554)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

排查方法:手工在虚拟打包机器上, 使用admin的账号,进行上面的命令。如果需要设置密码,那就说明没有配置ssh免登陆

ssh building@10.61.158.55 mkdir -p /Users/building/odin-h5ai/android-charmchat-sockpuppet/CharmChat/charmchat_1.0.0_gp_rb/20230829.7

解决方法:

  • 虚拟机器上执行

    [admin@bogon lastet]$ cd ~/.ssh
    [admin@bogon .ssh]$ ll
    total 12
    -rw------- 1 admin admin 1675 Aug 23 11:43 id_rsa
    -rw-r--r-- 1 admin admin 395 Aug 23 11:43 id_rsa.pub
    -rw-r--r-- 1 admin admin 363 Aug 23 14:42 known_hosts

将虚拟机的id_rsa.pub 文件download以后 上传到master 机器上。必须是复制文件的形式,否则会报错

  • master机器上执行

一定要追加写入,不要重新写入,否则所有的都需要重新弄。不放心的话可以提前备份一份/Users/building/.ssh/authorized_keys文件

cat id_rsa.pub >>/Users/building/.ssh/authorized_keys
  • 虚拟服务器上操作,检查配置是否生效

6.构建时jenkins提示JAVA_HOME有问题

  • 解决方案1:odin/script/Jenkinsfiles/android/Jenkinsfile 脚本中声明

    export PATH=/home/admin/jdk-11.0.20+8/bin/:$PATH

  • 解决方案2:

报错详情

构建类型: bundleOuterRelease
构建分支: nujoom_1.5.90_gp_rb
======java========
./bloodeye/odinAutoBuilder: line 9: java: command not found

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
构建时报错无法获取到网络资源libimcore-1.2.12.aar文件
  • 报错信息:

  FAILURE: Build completed with 3 failures.

  1: Task failed with an exception.
  -----------
  * What went wrong:
  Execution failed for task ':app:checkHertzOuterReleaseDuplicateClasses'.
  > Could not resolve all files for configuration ':app:hertzOuterReleaseRuntimeClasspath'.
     > Failed to transform libimcore-1.2.12.aar (com.im.live:libimcore:1.2.12) to match attributes {artifactType=enumerated-runtime-classes, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
        > Could not download libimcore-1.2.12.aar (com.im.live:libimcore:1.2.12)
           > Could not get resource 'http://maven.linkv.fun/repository/liveme-android/com/im/live/libimcore/1.2.12/libimcore-1.2.12.aar'.
              > Read timed out
  • 排查:直接在虚拟服务器上, 访问 对应的下载地址,可以访问通,但是下载非常慢。
  • 原因:这个访问链接linkv 超时,目前解决不了,遇到这种报错,就登录打包机上传该aar文件即可

  • 临时方案:手工mac本地下载libimcore-1.2.12.aar文件,手工上传到打包服务器中

    cd /home/admin/.gradle/caches/modules-2/files-2.1/com.im.live/libimcore/1.2.12
    mkdir 7e494aecb44925457b4cc28ed98bca8ba12f3e67

  • 终极解决方案:联系IT部门(切换网络出口,服务器刚才是香港出口访问的,咱们办公电脑是新加坡出口访问的,切换到新加坡出口就可以下载了)

7.构建时报错chmod: cannot access

chmod: cannot access '/home/admin/ramdisk/android-charmchat/bloodeye/odinAutoBuilder': No such file or directory

原因:因为对应的/home/admin/ramdisk/ 目录下 权限所有为root,而jenkins构建使用的是admin,所以提示无权限

解决方案:

chown -R admin:admin /home/admin/ramdisk/

8.构建时报错workspace/JOB_NAME@2

解决方案:

  1. 删除/home/admin/.jenkins/workspace 下所有对应的 JOB_NAME@ 的文件夹。 我当时试这个不好使

  2. 重新新建一个job,换一个名字。这个当时好使了。相当于 上面的job 彻底不要了

相关推荐
只会copy的搬运工36 分钟前
Jenkins 持续集成部署——Jenkins实战与运维(1)
运维·ci/cd·jenkins
测试杂货铺2 小时前
如何用postman做接口自动化测试及完美的可视化报告?
自动化测试·软件测试·测试工具·职场和发展·jenkins·压力测试·postman
一二小选手2 小时前
Postman接口测试工具
java·测试工具·postman
科马5 小时前
【Jenkins】持久化
java·运维·jenkins
测试老哥7 小时前
Jmeter测试脚本编写技巧
自动化测试·软件测试·功能测试·测试工具·jmeter·职场和发展·性能测试
编程、小哥哥7 小时前
在 Docker 中部署 Jenkins,并完成项目的构建和发布
servlet·docker·jenkins
爱学测试的李木子7 小时前
从0到1搭建 Android 自动化 python+appium 环境
android·软件测试·python·测试工具·自动化
霍格沃兹测试开发学社测试人社区10 小时前
软件测试丨性能测试工具-JMeter
软件测试·测试开发·测试工具·jmeter·性能测试
小张认为的测试11 小时前
Linux性能监控命令_nmon 安装与使用以及生成分析Excel图表
linux·服务器·测试工具·自动化·php·excel·压力测试
_oP_i12 小时前
.NET Core 项目配置到 Jenkins
运维·jenkins·.netcore