app编译脚本
# android编译
#!/bin/bash
time=`date "+%Y%m%d%H%M%S"`
commit_num=`git rev-parse --short HEAD`
project_code=saas
product_code=$project_code
versionlib_path=/data/Vsersion_Lib/$project_code
docker_images=
mapping_path=
dev_build_path=
run_build(){
sudo docker run -v /data/jenkins/jenkins_home/workspace/saas/$JOB_BASE_NAME:$mapping_path -v /data/gradle_cache/.gradle:/home/cirrus/.gradle --env GRADLE_USER_HOME=/home/cirrus/.gradle --workdir /build --rm $docker_images sh -c "$build_command"
if [ "$1" == "app_dev" ];then
echo "开始dev打包"
cd $dev_build_path
sudo mkdir -p $versionlib_path
sudo cp -rf app-release.apk $versionlib_path/"$JOB_BASE_NAME"_dev_"$time"_"$commit_num".apk
dev_new_package_name="$JOB_BASE_NAME"_dev_"$time"_"$commit_num".apk
echo $dev_new_package_name
# echo "开始stest打包"
# cd $stest_build_path
# sudo cp -rf app-stest-release.apk $versionlib_path/"$JOB_BASE_NAME"_test_"$time"_"$commit_num".apk
# test_new_package_name="$JOB_BASE_NAME"_test_"$time"_"$commit_num".apk
# echo $test_new_package_name
# echo "开始pro打包"
# cd $pro_build_path
# sudo cp -rf app-pro-release.apk $versionlib_path/"$JOB_BASE_NAME"_pro_"$time"_"$commit_num".apk
# pro_new_package_name="$JOB_BASE_NAME"_pro_"$time"_"$commit_num".apk
# echo $pro_new_package_name
curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$project_code"'","version_number":"'"$version_number"'","new_package_name":"'"$dev_new_package_name"'"}'
# curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$project_code"'","version_number":"'"$version_number"'","new_package_name":"'"$test_new_package_name"'"}'
# curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$project_code"'","version_number":"'"$version_number"'","new_package_name":"'"$pro_new_package_name"'"}'
elif [ "$1" == "app_test" ];then
echo "开始test打包"
cd $test_build_path
sudo mkdir -p $versionlib_path
sudo cp -rf app-release.apk $versionlib_path/"$JOB_BASE_NAME"_test_"$time"_"$commit_num".apk
test_new_package_name="$JOB_BASE_NAME"_test_"$time"_"$commit_num".apk
echo $test_new_package_name
curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$project_code"'","version_number":"'"$version_number"'","new_package_name":"'"$test_new_package_name"'"}'
elif [ "$1" == "app_release" ];then
echo "开始release打包"
cd $release_build_path
sudo mkdir -p $versionlib_path
sudo cp -rf app-release.apk $versionlib_path/"$JOB_BASE_NAME"_pro_"$time"_"$commit_num".apk
pro_new_package_name="$JOB_BASE_NAME"_pro_"$time"_"$commit_num".apk
echo $pro_new_package_name
curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$project_code"'","version_number":"'"$version_number"'","new_package_name":"'"$pro_new_package_name"'"}'
else
exit 1
fi
}
run_build1(){
if [ "$1" == "android_dev" ];then
docker_images=xxx/library/flutter:latest
mapping_path=/build
dev_build_path=/var/jenkins_home/workspace/$JOB_NAME/build/app/outputs/flutter-apk
build_command="flutter clean && flutter packages get && flutter build apk --no-sound-null-safety --dart-define=APP_ENV=dev"
run_build app_dev
elif [ "$1" == "android_test" ];then
docker_images=xxx/library/flutter:latest
mapping_path=/build
test_build_path=/var/jenkins_home/workspace/$JOB_NAME/build/app/outputs/flutter-apk
build_command="flutter clean && flutter packages get && flutter build apk --no-sound-null-safety --dart-define=APP_ENV=test"
run_build app_test
elif [ "$1" == "android_release" ];then
docker_images=xxx/library/flutter:latest
mapping_path=/build
release_build_path=/var/jenkins_home/workspace/$JOB_NAME/build/app/outputs/flutter-apk
build_command="flutter clean && flutter packages get && flutter build apk --no-sound-null-safety --dart-define=APP_ENV=release"
run_build app_release
else
exit 2
fi
}
function checkBuild(){
product=$1
version=$2
if [[ -z $product ]] || [[ -z $version ]];then
# 参数为空.
return 1
fi
info_path=http://172.16.30.217:9110/version/status
value=`curl -XGET "$info_path?product_code=$product_code&version_number=$version_number" |awk -F'lock_status":' '{print $2}'|awk -F, '{print $1}'`
if [[ $value -eq 0 ]];then
# 可以正常构建.
return 0
else
# 版本已锁定.
return 3
fi
}
res1=$(checkBuild $product_code $version_number)
res2=`echo $?`
if [[ $res2 -eq 1 ]];then
echo "版本号没有输入"
exit $res2
elif [[ $res2 -eq 3 ]];then
echo "对应的版本已锁定"
exit $res2
else
run_build1 $1
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# ios编译
#flutter build ipa --build-name=0.0.6 --build-number=15 --release --dart-define=APP_ENV=dev --no-sound-null-safety
#flutter build ipa --release --dart-define=APP_ENV=test --no-sound-null-safety
#open ./build/ios/archive/Runner.xcarchive
#flutter build apk --no-sound-null-safety --dart-define=APP_ENV=test
#flutter build ipa --release --dart-define=APP_ENV=dev --no-sound-null-safety
#xcodebuild -exportArchive -exportOptionsPlist ExportOptionsDevelopment.plist -archivePath $PWD/build/ios/archive/Runner.xcarchive -exportPath $PWD/build/ios/ipa/ -allowProvisioningUpdates
#cd ./ios && xcodebuild -workspace Runner.xcworkspace -scheme Runner -sdk iphoneos -configuration Release archive -archivePath $PWD/build/Runner.xcarchive && cd ..
#cd ./ios && fastlane ios build_dev && cd ..
#flutter build ipa --release --dart-define=APP_ENV=test --no-sound-null-safety
#cd ./ios && fastlane ios build_test && cd ..
#flutter build ios --release --dart-define=APP_ENV=dev --no-sound-null-safety
#cd ./ios && fastlane ios build_dev && cd ..
#
#flutter build ios --release --dart-define=APP_ENV=test --no-sound-null-safety
#cd ./ios && fastlane ios build_test && cd ..
#
time=`date "+%Y%m%d%H%M%S"`
commit_num=`git rev-parse --short HEAD`
product_code=saas
choice_env=$1
version_number=$2
export LANG=en_US.UTF-8
#JOB_NAME=scrm.ios
run_build(){
if [ "$1" == "app_dev" ];then
fir publish ./build/ios/outputs/saas_dev.ipa -c "jenkins自动打包上传" > /opt/jenkins/logs/saas/saas_dev.log
time=`date "+%Y%m%d%H%M%S"`
aa=`cat /opt/jenkins/logs/saas/saas_dev.log | grep Published | awk '{print $9}' | awk -F'/' '{print $4}'`
bb=`cat /opt/jenkins/logs/saas/saas_dev.log | grep Release | awk '{print $10}'`
new_package_name="$JOB_BASE_NAME"_dev_"$time"-"$commit_num"-"$aa"?release_id="$bb"
echo $new_package_name
echo $version_number
curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$product_code"'","'"version_number"'":"'"$version_number"'","new_package_name":"'"$new_package_name"'"}'
elif [ "$1" == "app_test" ];then
fir publish ./build/ios/outputs/saas_test.ipa -c "jenkins自动打包上传" > /opt/jenkins/logs/saas/saas_test.log
time=`date "+%Y%m%d%H%M%S"`
aa=`cat /opt/jenkins/logs/saas/saas_test.log | grep Published | awk '{print $9}' | awk -F'/' '{print $4}'`
bb=`cat /opt/jenkins/logs/saas/saas_test.log | grep Release | awk '{print $10}'`
new_package_name="$JOB_BASE_NAME"_test_"$time"-"$commit_num"-"$aa"?release_id="$bb"
echo $new_package_name
curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$product_code"'","'"version_number"'":"'"$version_number"'","new_package_name":"'"$new_package_name"'"}'
elif [ "$1" == "app_release" ];then
fir publish ./build/ios/outputs/saas_release.ipa -c "jenkins自动打包上传" > /opt/jenkins/logs/saas/saas_pro.log
time=`date "+%Y%m%d%H%M%S"`
aa=`cat /opt/jenkins/logs/saas/saas_pro.log | grep Published | awk '{print $9}' | awk -F'/' '{print $4}'`
bb=`cat /opt/jenkins/logs/saas/saas_pro.log | grep Release | awk '{print $10}'`
new_package_name="$JOB_BASE_NAME"_pro_"$time"-"$commit_num"-"$aa"?release_id="$bb"
echo $new_package_name
curl -H "Content-Type:application/json" -XPOST http://172.16.30.217:9110/version/modify -d '{"product_code":"'"$product_code"'","'"version_number"'":"'"$version_number"'","new_package_name":"'"$new_package_name"'"}'
else
exit 1
fi
}
clean_build(){
flutter doctor
flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec
rm ios/Podfile
}
run_build1(){
if [ $choice_env == "ios_dev" ];then
clean_build
flutter build ipa --export-options-plist ./ios/ExportOptionsDevelopment.plist --release --dart-define=APP_ENV=dev --no-sound-null-safety
mkdir -p ./build/ios/outputs
cp -r ./build/ios/ipa/scrm_app.ipa ./build/ios/outputs/saas_dev.ipa
run_build app_dev
elif [ $choice_env == "ios_test" ];then
clean_build
flutter build ipa --export-options-plist ./ios/ExportOptionsDevelopment.plist --release --dart-define=APP_ENV=test --no-sound-null-safety
mkdir -p ./build/ios/outputs
cp -r ./build/ios/ipa/scrm_app.ipa ./build/ios/outputs/saas_test.ipa
run_build app_test
elif [ $choice_env == "ios_release" ];then
clean_build
flutter build ipa --export-options-plist ./ios/ExportOptionsDevelopment.plist --release --dart-define=APP_ENV=release --no-sound-null-safety
mkdir -p ./build/ios/outputs
cp -r ./build/ios/ipa/scrm_app.ipa ./build/ios/outputs/saas_release.ipa
run_build app_release
elif [ $choice_env == "ios_appstore" ];then
cd ./ios && fastlane ios sign_xcarchive_and_publish
else
exit 2
fi
}
function checkBuild(){
product=$1
version=$2
if [[ -z $product ]] || [[ -z $version ]];then
# 参数为空.
return 1
fi
info_path=http://172.16.30.217:9110/version/status
value=`curl -XGET "$info_path?product_code=$product_code&version_number=$version_number" |awk -F'lock_status":' '{print $2}'|awk -F, '{print $1}'`
if [[ $value -eq 0 ]];then
# 可以正常构建.
return 0
else
# 版本已锁定.
return 3
fi
}
res1=$(checkBuild $product_code $version_number)
res2=`echo $?`
if [[ $res2 -eq 1 ]];then
echo "版本号没有输入"
exit $res2
elif [[ $res2 -eq 3 ]];then
echo "对应的版本已锁定"
exit $res2
else
run_build1
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
上次更新: 2023/01/09, 17:10:59