jenkins配置android发布
# 1、配置安卓需要编译的环境节点
参考:CentOS7安装Android SDK | 章工运维 (opens new window)
# 2、发布脚本
#!/bin/bash
time=`date "+%Y%m%d%H%M%S"`
commit_num=`git rev-parse --short HEAD`
project_code=gg
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/gg/$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.xxx: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.xxx: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.xxx: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.xxx: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.xxx: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
mapping_path=/build
dev_build_path=/var/jenkins_home/workspace/$JOB_NAME/build/app/outputs/flutter-apk
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
mapping_path=/build
test_build_path=/var/jenkins_home/workspace/$JOB_NAME/build/app/outputs/flutter-apk
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
mapping_path=/build
release_build_path=/var/jenkins_home/workspace/$JOB_NAME/build/app/outputs/flutter-apk
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
}
run_build1 $1
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
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
jenkinsfile脚本
pipeline {
agent { label "jenkins-slave5" }
parameters {
string(name: 'version_number', defaultValue: '', description: '')
string(name: 'product_code', defaultValue: 'gg', description: '')
choice choices: ['dev', 'test', 'release', 'ALL'], description: '请选择要打包的环境', name: 'choice_value'
gitParameter (branch:'', branchFilter: 'origin/(.*)', defaultValue: 'master', description: '选择将要构建的分支', name: 'TAG', quickFilterEnabled: true, selectedValue: 'TOP', sortMode: 'DESCENDING_SMART', tagFilter: '*', type: 'PT_BRANCH_TAG', useRepository: 'ssh://git@172.16.30.xxx:xxx/gg/scrm_app.git')
}
stages {
stage('CleanWorkspace') {
steps {
cleanWs()
}
}
stage('拉取代码') {
steps {
dir("${WORKSPACE}/"){
script {
try {
checkout([$class: 'GitSCM', branches: [[name: '$TAG']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[url: "ssh://git@172.16.30.xxx:xxx/gg/scrm_app.git"]]])
}catch(exc) {
env.REASON = "拉取代码出错"
throw(exc)
}
}
}
}
}
stage('打包dev环境') {
when {
expression { params.choice_value == 'dev'}
}
steps {
sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_dev'
}
}
stage('打包test环境') {
when {
expression { params.choice_value == 'test'}
}
steps {
sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_test'
}
}
stage('打包release环境') {
when {
expression { params.choice_value == 'release'}
}
steps {
sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_release'
}
}
stage('打包ALL环境') {
when {
expression { params.choice_value == 'ALL'}
}
parallel {
stage('打包dev环境') {
steps {
sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_dev'
}
}
stage('打包test环境') {
// when {
// expression { params.choice_value == 'ALL'}
// }
steps {
sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_test'
}
}
stage('打包release环境') {
// when {
// expression { params.choice_value == 'ALL'}
// }
steps {
sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_release'
}
}
}
// steps {
// sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_dev'
// sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_test'
// sh label: '', script: '/var/jenkins_home/script/gg/android_build01.sh android_release'
// }
}
}
}
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
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
上次更新: 2023/06/25, 16:58:02