项目配置jenkins,bugly记录

2018-11-28  本文已影响0人  wg刚

一、配置jenkins

1、新建一个ExportOptions.plist

配置如下
其中:teamID可以登录苹果开发者中心查看账号信息得到
provisioningProfiles字典key为app的bundleId,value为描述文件名字

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>teamID</key>
    <string>49T87S5RLN</string>
    <key> teamID </key>
    <string>app-store</string>
    <key>uploadSymbols</key>
    <true/>
    <key>method</key>
    <string>development</string>
    <key>compileBitcode</key>
    <false/>
    <key>provisioningProfiles</key>
    <dict>
        <key>com.bozhong.HuDataReportPlatform</key>
        <string>HuDataReportPlatform_devProfile</string>
    </dict>
</dict>
</plist>
2、打开jenkins,新建一个项目

这里可以选择一个已经完成的作为模板,然后再做对应的修改即可

3、 修改脚本
#!/bin/bash

#===========================================================
#

name=ios_HuDataReportPlatform_shell
project_path=${HOME}/.jenkins/workspace/${name}

cd ${project_path}

${pod repo update HuModularizationSpecs}

#env_array=("SIT" "DEV" "UAT" "PRO")
env_array=("SIT" "DEV" "UAT")

time="$(date +"%Y%m%d_%H%M%S")"

server="https://jenkins.317hu.com:443"
root="/usr/local/var/www"
home="317/iOS"

local="${time}"
downPath="${local}/${time}.html"
dirRoot="dir"
backupRoot="${dirRoot}/backup"
dirPath="${dirRoot}/download.html"
backupPath="${backupRoot}/download${time}.html"

remote="${root}/${home}"
remoteDirRoot="${root}/317"
remoteDirPath="${remoteDirRoot}/${dirPath}"

project_name=$(ls | grep xcodeproj | awk -F .xcodeproj '{print $1}')
app_infoplist_path=${project_path}/HuDataReportPlatform/Info.plist
export_optionsplist_path=${project_path}/HuDataReportPlatform/ExportOptions.plist 
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print sys-clientVersion" "${app_infoplist_path}")
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${app_infoplist_path}")
bundleDisplayName=$(/usr/libexec/PlistBuddy -c "print CFBundleDisplayName" "${app_infoplist_path}")

configuration="Debug"
#configuration="Release"
#signIdentity="iPhone Developer: Curious Keep (R8SKGR3KR7)"
#signIdentity="iPhone Developer: 雨辰 huang (3JN4KWGWUD)"

#signIdentity="iPhone Distribution: Hangzhou Bozhong Information&Technology Co., Ltd. (49T87S5RLN)"
#provisioningProfile="orgQqhlNursingAdHoc"

gitRepo=$(git log --pretty=format:"%H " -1)
gitBranch=$(git branch | grep '*')
gitBranch=$(echo ${gitBranch:2})

#===========================================================

if [ ! -d "${local}" ]; then
    mkdir -p ${local}
fi

if [ ! -d "${dirRoot}" ]; then
    mkdir -p ${backupRoot}
fi

if [ ! -d "${remote}" ]; then
    mkdir -p ${remote}
fi

#===========================================================
#           DirectoryHtml


DirHtmlHeader="<html>
    <head><title>317hu iOS下载目录</title></head>
    <meta charset=\"UTF-8\">
<div style=\"text-align:center;\">
    <a style=\"margin-top:10%;display:inline-block;font-size:20px;\"></a><br>"
DirHtmlContent="    <a style=\"font-size:15px;\" href=\"../../${home}/${downPath}\"><h1>数据填报-${time}-${bundleShortVersion}</h1></a>"
DirHtmlTail="</div>
</html>"

if [ ! -f "${remoteDirPath}" ]; then

touch ${dirPath}

echo "${DirHtmlHeader}" >> ${dirPath}
echo "${DirHtmlContent}" >> ${dirPath}
echo "${DirHtmlTail}" >> ${dirPath}
cp ${dirPath} ${backupPath}

else

#--------------------------------------------------------
#NR=$(awk '{print NR}' ${dirPath} | tail -n1)
#echo ${NR}
#INSERT=$[${NR}-1]
#
#cpdown=$(sed "${INSERT},${NR}d" ${dirPath} > tmp.html)
#${cpdown}
#
#echo "${DirHtmlContent}" >> tmp.html
#mv tmp.html ${dirPath}
#--------------------------------------------------------

echo "${DirHtmlHeader}" >> tmp.html
echo "${DirHtmlContent}" >> tmp.html
sed "1,5d" ${remoteDirPath} >> tmp.html
mv tmp.html ${dirPath}
cp ${dirPath} ${backupPath}

fi

#===========================================================
#           download.html

htmlHeader="<html>
    <head><title>317hu iOS下载页面</title></head>
    <meta charset=\"UTF-8\">
<div style=\"text-align:center;\">
    <a style=\"margin-top:10%;display:inline-block;font-size:20px;\"></a><br>"

htmlTail="  <span style=\"text-align:center;font-size:30px;\">gitRepo:${gitRepo}</span><br>
            <span style=\"text-align:center;font-size:30px;\">gitBranch:${gitBranch}</span><br>
            <span style=\"text-align:center;font-size:30px;\">appVersion:${bundleShortVersion}</span><br>
            <a style=\"margin-top:80%;display:inline-block;font-size:20px;\" href=\"${server}/ca.crt\"><h1>出现无法连接到,请下载安装证书</h1></a><br>
    <span style=\"text-align:center;font-size:30px;\">仍有问题请联系iOS开发组</span>
</div>
</html>"

touch ${downPath}

echo "${htmlHeader}" >> ${downPath}

#===========================================================

for i in ${env_array[@]}
do


if [ ! -d "build" ]; then
xcodebuild clean -configuration Debug
fi

env=${i}

build_scheme="${project_name}-${env}"
build_config="${configuration}-${env}"

if [ ${i} == "PRO" ]; then
    build_scheme="${project_name}"
    build_config="${configuration}"  
fi


export_optionsplist_path=${project_path}/HuDataReportPlatform/ExportOptions.plist 
echo "wy=${configuration}=${build_config}=${export_optionsplist_path}"

archive_name="${build_scheme}${time}.xcarchive"
archive_path="archive/$archive_name"
ipa_name="${build_scheme}${time}"
ipa_path="${local}/${ipa_name}"


build_cmd='xcodebuild archive -workspace '${project_name}.xcworkspace' -scheme '${build_scheme}' -configuration '${build_config}' -archivePath '${archive_path}
#build_cmd='xcodebuild archive -project '${project_name}.xcodeproj' -scheme '${build_scheme}' -configuration '${build_config}' -archivePath '${archive_path}
${build_cmd}

#archivie_cmd=$(xcodebuild -exportArchive -archivePath ${archive_path} -exportPath ${ipa_path} -exportFormat ipa -exportSigningIdentity "${signIdentity}")
#archivie_cmd=$(xcodebuild -exportArchive -archivePath ${archive_path} -exportPath ${ipa_path} -exportFormat ipa -exportProvisioningProfile "${provisioningProfile}")
archivie_cmd=$(xcodebuild -exportArchive -archivePath ${archive_path} -exportPath ${ipa_path} -exportOptionsPlist ${export_optionsplist_path} -allowProvisioningUpdates)

${archive_cmd}

plistName="${build_scheme}${time}.plist"
plistPath="${local}/${plistName}"

touch ${plistPath}

createPlist="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
    <key>items</key>
    <array>
        <dict>
            <key>assets</key>
            <array>
                <dict>
                    <key>kind</key>
                    <string>software-package</string>
                    <key>url</key>
                    <string>${server}/${home}/${ipa_path}/${build_scheme}.ipa</string>
                </dict>
            </array>
            <key>metadata</key>
            <dict>
                <key>bundle-identifier</key>
                <string>com.bozhong.HuDataReportPlatform</string>
                <key>bundle-version</key>
                <string>${bundleShortVersion}</string>
                <key>kind</key>
                <string>software</string>
                <key>subtitle</key>
                <string>${project_name}</string>
                <key>title</key>
                <string>${build_scheme}</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>"

echo "${createPlist}" >> ${plistPath}

htmlContent="    <a style=\"font-size:20px;\" href=\"itms-services://?action=download-manifest&url=${server}/${home}/${plistPath}\"><h1>iOS APP(${i}环境)${time}</h1></a><br>"

echo "${htmlContent}" >> ${downPath}

done

echo "${htmlTail}" >> ${downPath}

#===========================================================

cp -r ${local} ${remote}
cp -r ${dirRoot} ${remoteDirRoot}

rm -r ${local}
rm -r ${dirRoot}
rm -r archive
rm -r build
4、上传代码到对应的代码仓库,配置项目证书和描述文件
5、点击构建,看看是否成功,有错误再根据错误修改。

二、配置bugly

1、登录bugly,新建产品
2、获取产品的app id
3、回到代码

在appdeledate里添加代码

//初始化腾讯Bugly组件(异常捕获)
- (void)startBugly
{
        BuglyConfig * config = [[BuglyConfig alloc] init];
        // 设置自定义日志上报的级别,默认不上报自定义日志
        config.reportLogLevel = BuglyLogLevelWarn;
        config.debugMode = YES;
        
        [Bugly startWithAppId:@"cb3db1992a" config:config];
}
4、上传符号表
上一篇 下一篇

猜你喜欢

热点阅读