美文网首页
Jenkins脚本

Jenkins脚本

作者: oldDevil | 来源:发表于2020-08-17 10:16 被阅读0次
    #!/bin/bash
    security unlock-keychain -p "本机密码" ~/Library/Keychains/login.keychain-db
    
    # 工程名
    APP_NAME="xxxApp"
    BUNDLE_DISPLAY_NAME="xxx"
    # 证书
    CODE_SIGN_DEVELOPER="iPhone Distribution"
    # info.plist路径
    project_infoplist_path="./${APP_NAME}/Info.plist"
    
    #取版本号
    bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
    
    #取build值
    bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
    
    DATE="$(date +%Y%m%d)"
    IPANAME="${APP_NAME}_$(date +%F-%T)/${APP_NAME}.ipa"
    
    #要上传的ipa文件路径
    IPA_PATH=~/Desktop/IPAS/${Target}_$(date +%F-%T)
    BUILDPATH=~/Desktop
    ARCHIVEPATH=${BUILDPATH}/Archives/${APP_NAME}/${APP_NAME}_$(date +%F-%T)/${APP_NAME}.xcarchive
    echo ${IPA_PATH}
    #echo "${IPA_PATH}">> text.txt
    
    #集成有Cocopods的用法
    echo "=================clean================="
    xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${Target}"  -configuration 'Release' clean
    
    echo "+++++++++++++++++build+++++++++++++++++"
    #xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${Target}" -sdk iphoneos -configuration 'Release' SYMROOT='$(PWD)'
    
    #xcrun -sdk iphoneos PackageApplication "./Release-iphoneos/${APP_NAME}Test.app" -o ~/"${IPANAME}"
    xcodebuild archive -workspace ${APP_NAME}.xcworkspace -scheme ${Target} -archivePath ${ARCHIVEPATH} -configuration 'Release'
    xcodebuild -exportArchive -archivePath ${ARCHIVEPATH} -exportPath ${IPA_PATH} -exportOptionsPlist /Users/test/Downloads/ExportOptions.plist 
    
    #蒲公英上的User Key
    uKey="xxxxx"
    #蒲公英上的API Key
    apiKey="xxxx"
    
    #执行上传至蒲公英的命令
    echo "++++++++++++++upload+++++++++++++"
    
    function getJsonValuesByAwk() {
        awk -v json="$1" -v key="$2" -v defaultValue="$3" 'BEGIN{
            foundKeyCount = 0
            while (length(json) > 0) {
                # pos = index(json, "\""key"\""); ## 这行更快一些,但是如果有value是字符串,且刚好与要查找的key相同,会被误认为是key而导致值获取错误
                pos = match(json, "\""key"\"[ \\t]*?:[ \\t]*");
                if (pos == 0) {if (foundKeyCount == 0) {print defaultValue;} exit 0;}
    
                ++foundKeyCount;
                start = 0; stop = 0; layer = 0;
                for (i = pos + length(key) + 1; i <= length(json); ++i) {
                    lastChar = substr(json, i - 1, 1)
                    currChar = substr(json, i, 1)
    
                    if (start <= 0) {
                        if (lastChar == ":") {
                            start = currChar == " " ? i + 1: i;
                            if (currChar == "{" || currChar == "[") {
                                layer = 1;
                            }
                        }
                    } else {
                        if (currChar == "{" || currChar == "[") {
                            ++layer;
                        }
                        if (currChar == "}" || currChar == "]") {
                            --layer;
                        }
                        if ((currChar == "," || currChar == "}" || currChar == "]") && layer <= 0) {
                            stop = currChar == "," ? i : i + 1 + layer;
                            break;
                        }
                    }
                }
    
                if (start <= 0 || stop <= 0 || start > length(json) || stop > length(json) || start >= stop) {
                    if (foundKeyCount == 0) {print defaultValue;} exit 0;
                } else {
                    print substr(json, start, stop - start);
                }
    
                json = substr(json, stop + 1, length(json) - stop)
            }
        }'
    }
    
    upload_result=$(curl -F "file=@${IPA_PATH}/${Target}.ipa" -F "uKey=${uKey}" -F "_api_key=${apiKey}" -F "updateDescription=${Distribution_Comment}" https://upload.pgyer.com/apiv1/app/upload)
    #upload_result=$(curl -F 'file=@${IPA_PATH}/${Target}.ipa' -F '_api_key=${apiKey}' https://www.pgyer.com/apiv2/app/upload)
    
    data=$(getJsonValuesByAwk "$upload_result" "data" "defaultValue")
    #data=$(sed -e 's/^"//' -e 's/"$//' <<<"$data")
    
    qrcode=$(getJsonValuesByAwk "$data" "appQRCodeURL" "defaultValue")
    qrcode=$(sed -e 's/^"//' -e 's/"$//' <<<"$qrcode")
    
    appUpdated=$(getJsonValuesByAwk "$data" "appUpdated" "defaultValue")
    appUpdated=$(sed -e 's/^"//' -e 's/"$//' <<<"$appUpdated")
    
    appVersion=$(getJsonValuesByAwk "$data" "appVersion" "defaultValue")
    appVersion=$(sed -e 's/^"//' -e 's/"$//' <<<"$appVersion")
    
    appBuildVersion=$(getJsonValuesByAwk "$data" "appBuildVersion" "defaultValue")
    appBuildVersion=$(sed -e 's/^"//' -e 's/"$//' <<<"$appBuildVersion")
    
    screenshot="![screenshot](${qrcode})"
    
    curl -X POST "https://oapi.dingtalk.com/robot/send?access_token=3a6006f2f5c892e832dd830a1d16a927c5ae5d84558f71f17ca92e8714e7398e " \
        -H "Content-Type: application/json" \
        -d "{\"msgtype\": \"markdown\", \"markdown\": { \"text\": \"### xxx_iOS\n\nTarget:${Target}\n\n版本信息:${appVersion}(build ${appBuildVersion})\n'${screenshot}'\n ###### 构建时间:${appUpdated}\", \"title\": \"#### xxx_iOS\"}}"
    #    -d "{\"msgtype\": \"actionCard\", \"actionCard\": { \"title\":\"${Target}${BUNDLE_DISPLAY_NAME}_iOS构建成功\", \"text\": \" ${Target}${BUNDLE_DISPLAY_NAME}构建成功\n\n\", \"singleTitle\": \"点击安装\", \"singleURL\": \"${appUrl}\"}}"   
        
    

    相关文章

      网友评论

          本文标题:Jenkins脚本

          本文链接:https://www.haomeiwen.com/subject/fabfjktx.html