mac/ubuntu/windows 安装布署Jenkins编译flutter android & ios

 

一、安装Jenkins

1、Mac上安装Jenkins

在中端中执行 brew services start jenkins-lts 启动jenkins

# 安装jenkins
brew install jenkins-lts
# 启动服务
brew upgrade jenkins
# 启动服务
brew services start jenkins-lts
# 重启服务
brew services stop jenkins-lts
# 关闭服务
brew services restart jenkins-lts

2、ubuntu安装jenkins

# 1. 更新包索引
sudo apt update
# 2. 添加jenkins GPG密钥
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
# 进行第二步的时候可能报错 “gpg: no valid OpenPGP data found” ,是wget命令版本过旧问题,这里用下面命令即可
wget --no-check-certificate -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
# 3. 将jenkins存储库添加到系统
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
# 4. 更新包索引
sudo apt update
# 5. 安装jenkins
sudo apt install jenkins
# 6. 启动jenkins
sudo systemctl start jenkins
# 6.2 启动jenkins的其他方式
nohup java -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -jar ~/jenkins.war --httpPort=8080 2>&1 &
## 启动jenkins后可以使用下面命令查看
sudo systemctl status jenkins # 查看运行状态
lsof -i:8080 # jenkins默认端口是8080,查看端口运行状态

3、windows上安装jenkins

https://www.jenkins.io/download/

https://sg.mirror.servanamanaged.com/jenkins/windows/2.421/jenkins.msi

 

二、安装扩展工具

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

brew install nginx git 
brew install mongodb-atlas
brew install neofetch
brew install chromium
brew install xcode
brew install CocoaPods
pip3 install qrencode

三、配置jenkins

 1、开始配置jenkins

在浏览器中输入 http://localhost:8080/ 配置jenkins

cat /var/lib/jenkins/secrets/initialAdminPassword

 复制密码输入到管理员密码,登录系统,插件安装选择推荐插件

 2、安装自定义插件

点击Manage Jenkins http://10.10.10.80:8080/manage/pluginManager/available 

搜索 GitLab Plugin 、Publish Over FTP 、description setter 并安装,完成后执行 brew services restart jenkins-lts 重启jenkins

 

 3、配置Html展示

点击 http://localhost:8080/manage/configureSecurity/, 搜索 Markup Formatter,目的修改Build描述信息为html,在描述信息中增加显示二维码下载地址。

 

三、配置一个安卓编译任务

 1、创建一个安卓编译任务

点击 http://localhost:8080/view/all/newJob 创建一个任务,新建任务-》构建一个自由风格的软件项目

 

2、配置编译选项(自定义变量),debug/release版本等

勾选 This project is parameterized

 3、配置gitlab源码地址和账号密码

Git中配置

4、配置编译脚本

在 Build Steps 中选择 Execute shell

 

source ~/.bashrc
rm -rf build/app/outputs/
flutter build apk --${BUILD_TYPE} --build-number=${VERSION_CODE} --build-name=${VERSION_NAME}-${BUILD_NUMBER} --flavor=${CHANNEL_TYPE} --obfuscate --split-debug-info=debug_info
ls build/app/outputs/flutter-apk/
ls build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/
BUILD_APK_PATH=build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/VideoMate-${CHANNEL_TYPE}-v${VERSION_CODE}-${VERSION_NAME}-${BUILD_NUMBER}-${BUILD_TYPE}.apk
BUILD_APK_ULR=${BUILD_URL}artifact/${BUILD_APK_PATH}
BUILD_APK_QR_PATH=build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/videomate_android.png
BUILD_APK_QR_ULR=${BUILD_URL}artifact/${BUILD_APK_QR_PATH}
qrencode -o ${BUILD_APK_QR_PATH} "${BUILD_APK_ULR}"

 

 

5、配置编译后展示的文件

在 Add post-build action 中选择 Archive the artifacts

 

build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/*

✓  Built build
<img src=${BUILD_URL}artifact/build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/videomate_android.png width=200px height=200px><br><a href=${BUILD_URL}artifact/build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/VideoMate-${CHANNEL_TYPE}-v${VERSION_CODE}-${VERSION_NAME}-${BUILD_NUMBER}-${BUILD_TYPE}.apk> 连接 WiFi-PI5G 网络,扫描二维码下载体验</a>

FAILED
非常抱歉,编译失败了哦,请联系xxx~

 

 

 6、配置上传到ftp

1. 先到System Configuration http://10.10.10.80:8080/manage/configure 中添加ftp

搜索 Publish over FTP

 

 2. 再回到项目配置页面 配置编译完成后上传到ftp

Add post-build action 中选择 Send build artifacts over FTP

 

build/app/outputs/apk/${CHANNEL_TYPE}/${BUILD_TYPE}/*.apk
build/app/outputs/
${JOB_BASE_NAME}/${BUILD_TYPE}/${BUILD_NUMBER}

 

四、配置一个IOS编译任务

1、copy生成一个新项目

点击 http://localhost:8080/view/all/newJob  填写item名字,copy from 之前创建的android项目

 

2、修改编译脚本

在新项目的 Configuration 中配置编译脚本

source ~/.bashrc
BUILD_IPA_PATH=build/ios/ipa/videomate.ipa
BUILD_IPA_ULR=${BUILD_URL}artifact/${BUILD_IPA_PATH}
BUILD_IPA_QR_PATH=build/ios/ipa/videomate_ios.png
BUILD_IPA_QR_ULR=${BUILD_URL}artifact/${BUILD_IPA_QR_PATH}
flutter build ipa --${BUILD_TYPE} --build-number=${VERSION_CODE} --build-name=${VERSION_CODE}.${BUILD_NUMBER} --obfuscate --split-debug-info=debug_info
qrencode -o ${BUILD_IPA_QR_PATH} "${BUILD_IPA_ULR}"

编译后的产物

Built IPA to
<img src=${BUILD_URL}artifact/build/ios/ipa/videomate_ios.png width=200px height=200px><br><a href=${BUILD_URL}artifact/build/ios/ipa/videomate.ipa> 连接 WiFi-PI5G 网络,扫描二维码下载体验</a>

FAILD
不好意思,编译失败了哦,请联系xxx~

 

 

五、一些问题处理

1、使用ip地址无法访问页面

当配置完Jenkins,准备测试时,是无法通过地址访问你的页面,本机上也只能使用localhost和127.0.0.1打开页面。
需要在以下两个文件中,配置0.0.0.0

~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist
/opt/homebrew/Cellar/jenkins-lts/2.401.3/homebrew.mxcl.jenkins-lts.plist

vim ~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist
vim /opt/homebrew/Cellar/jenkins-lts/2.401.3/homebrew.mxcl.jenkins-lts.plist
vim ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist 
vim /opt/homebrew/Cellar/jenkins/2.434/homebrew.mxcl.jenkins.plist

 

 

2、启用安全权限导致页面无法访问

 在下面的权限面板修改配置后导致无权限访问jenkin,可以通过在别个电脑上新开几个jenkins,然后 cp ~/.jenkins/config.xml 到你的电脑上覆盖同名文件,同时做好备份

cp ~/.jenkins/config.xml ~/.jenkins/config.xml.bk

3、问题 Warning: CocoaPods not installed. Skipping pod install.

lib/main.dart:1
Automatically signing iOS for device deployment using specified development team in Xcode project: xxxxxx
Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
  Without CocoaPods, plugins will not work on iOS or macOS.
  For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

Exception: CocoaPods not installed or not in valid state.
Exited (sigterm)

  

网上说通过bash命令打开Android studio,点击Run按钮编译安装apk或者ipa

open /Applications/Android\ Studio.app

  解释原因是:

 于是我直接将所有环境都配置在 ~/.bashrc 中;先查找下 CocoaPods 的执行文件 pod:

➜  ~ whereis pod
pod: /opt/homebrew/bin/pod

再将 /opt/homebrew/bin 添加到 ~/.bashrc 文件中PATH环境变量中 vim ~/.bashrc

 1 export PYTHON3_HOME=/Library/Frameworks/Python.framework/Versions/3.11
 2 export PYTHON_HOME=$PYTHON3_HOME
 3 export PYTHON_PATH=$PYTHON_HOME
 4 #alias python=/usr/local/bin/python2
 5 alias python=/usr/local/bin/python3
 6 
 7 
 8 export JAVA20_HOME=/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home
 9 export JAVA17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
10 export JAVA11_HOME=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
11 export JAVA8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
12 export JAVA_HOME=$JAVA17_HOME
13 export JAVA_PATH=$JAVA_HOME/bin
14 
15 export ANDROID_HOME=/Users/max/Library/Android/sdk
16 export ANDROID_PATH=$ANDROID_HOME/build-tools/34.0.0:$ANDROID_HOME/platform-tools
17 export ANDROID_SDK_ROOT=$ANDROID_HOME
18 
19 export NDK_HOME=/Users/max/bin/ndk/android-ndk-r10
20 export NDK_PATH=$NDK_HOME
21 
22 export FLUTTER_ROOT=/Users/max/bin/flutter_sdk/flutter_git
23 #export FLUTTER_ROOT=/Users/max/bin/flutter_sdk/flutter2.5.0
24 export PUB_HOSTED_URL=https://pub.flutter-io.cn
25 export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
26 export FLUTTER_PATH=$FLUTTER_ROOT/bin
27 
28 #export DART_HOME=/opt/homebrew/opt/dart@3.0
29 #export DART_HOME=/Users/max/bin/dart_sdk/dart2.12.0
30 export DART_HOME=/Users/max/bin/dart_sdk/dart2.19.0
31 export DART_PATH=$DART_HOME/bin
32 
33 export TOMCAT_HOME=/Users/max/bin/tomcat/apache-tomcat-11.0.0-M10
34 export TOMCAT_PATH=$TOMCAT_HOME/bin
35 
36 export DIFF_PATH=/Users/max/bin/diff 
37 export VERSION_PATH=/Users/max/bin/version
38 export SQLITE_PATH=/Users/max/bin/sqlite 
39 
40 export ANT_HOME=/Users/max/bin/ant/apache-ant-1.10.5
41 export ANT_PATH=$ANT_HOME/bin
42 
43 export DEAPK_HOME=~/bin/de_apk
44 export DEAPK_PATH=~/bin:$DEAPK_HOME:$DE_APK_HOME/apktool:$DE_APK_HOME/dex2jar:$DE_APK_HOME/jd-gui-osx
45 
46 export JEB_PATH=~/bin/jeb/jeb4.0
47 
48 export ANDROID_TOOLS_PATH=/Users/max/bin/android_tools/uiautomatorviewer 
49 
50 export MY_PATH=$PYTHON_PATH:$JAVA_PATH:$ANDROID_PATH:$DEAPK_PATH:$JEB_PATH:$NDK_PATH:$FLUTTER_PATH:$DART_PATH:$DIFF_PATH:$VERSION_PATH:$SQLITE_PATH:$ANT_PATH:$ANDROID_TOOLS_PATH:$TOMCAT_PATH
51 
52 export PATH=$MY_PATH:$PATH:$HOME/bin:/sbin:/usr/bin:/usr/sbin:/opt/homebrew/bin
53 
54 
55 export CHROME_EXECUTABLE=/opt/homebrew/bin/chromium
56 
57 export PYTHONHTTPSVERIFY=0
58 #export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
59 # set the number of open files to be 1024
60 ulimit -S -n 2048
View Code

再在编译Jenkins 编译工程 Build Steps -> Execute shell 编译第一行添加 source ~/.bashrc

 

 

 
posted @ 2023-08-22 16:52  狐狸已化妖  阅读(428)  评论(0编辑  收藏  举报