美文网首页
Jenkins iOS搭建(无需安装Keychains插件)

Jenkins iOS搭建(无需安装Keychains插件)

作者: 吕建雄 | 来源:发表于2023-04-01 08:46 被阅读0次

    #bin/bsah - l

    export LANG=en_US.UTF-8

    export LANGUAGE=en_US.UTF-8

    export LC_ALL=en_US.UTF-8

    ## 当前目录

    SORCEPATH=${WORKSPACE}

    ## 项目名

    TARGET_NAME="xxx"

    ## Scheme名(此处根据环境来获取)

    SCHEME="xxx"

    ## 编译类型 Release | Debug

    BUILD_TYPE=Debug

    echo $SORCEPATH

    cd $SORCEPATH

    pod update --verbose --no-repo-update

    ## workspace名

    SPACE=${WORKSPACE}/${TARGET_NAME}.xcworkspace

    ##xcarchive文件的存放路径

    ARCHIVEPATH=$SORCEPATH/build/$SCHEME.xcarchive

    ## ipa文件的存放路径

    EXPORTPATH=$SORCEPATH/build/$SCHEME

    ## ExportOptions.plist文件的存放路径(此处根据环境来获取)

    ## ReleaseExportOptions 文件,可以通过xcoce archive先生产一个ipa包,然后从里面取出ExportOptions.plist即可(注意:生成ipa时必须是手动选择证书,不能使用自动模式)

    EXPORTOPTIONSPLIST=$SORCEPATH/ExportOptions/ReleaseExportOptions.plist

    ## 导出后的ipa路径

    EXPORTPATHIPA=$SORCEPATH/build/$SCHEME/$SCHEME.ipa

    echo -e "============First Build Clean============"

     ## 清理缓存

    #xcodebuild clean -workspace $SPACE -scheme $SCHEME -configuration $BUILD_TYPE

    xcodebuild clean -workspace $SPACE -scheme ${SCHEME} -configuration ${BUILD_TYPE}

    echo -e "============Build Clean============"

    ## 输出关键信息

    echo -e "  TARGET_NAME    : ${TARGET_NAME}"

    echo -e "  BUILD_TYPE    : ${BUILD_TYPE}"

    echo -e "  SORCEPATH    : ${SORCEPATH}"

    echo -e "  ARCHIVEPATH    : ${ARCHIVEPATH}"

    echo -e "  EXPORTPATH    : ${EXPORTPATH}"

    echo -e "  EXPORTOPTIONSPLIST    : ${EXPORTOPTIONSPLIST}"

    mkdir -p build

    echo -e "============Build Archive============"

    #xcodebuild archive -archivePath $ARCHIVEPATH -project $TARGET_NAME -workspace $SPACE -scheme $SCHEME -configuration $BUILD_TYPE

    ## 导出archive包

    xcodebuild archive -workspace ${SPACE} -scheme ${SCHEME} -archivePath $ARCHIVEPATH -configuration $BUILD_TYPE

    echo -e "============Export IPA============"

    ## 导出IPA包

    xcodebuild -exportArchive -archivePath $ARCHIVEPATH -exportPath ${EXPORTPATH} -exportOptionsPlist ${EXPORTOPTIONSPLIST}

    echo -e "============Export IPA SUCCESS============"

    ## 编译完成时间

    BUILD_DATE="$(date +'%Y%m%d_%H%M')"

    ## info.plist路径

    PROJECT_INFOPLIST_PATH="${ARCHIVEPATH}/Info.plist"

    ## 取版本号

    BUNDLESHORTVERSION=$(/usr/libexec/PlistBuddy -c "print :ApplicationProperties:CFBundleShortVersionString" "${PROJECT_INFOPLIST_PATH}")

    ## 取build值

    VERSION=$(/usr/libexec/PlistBuddy -c "print :ApplicationProperties:CFBundleVersion" "${PROJECT_INFOPLIST_PATH}")

    echo -e "  BUNDLESHORTVERSION    : ${BUNDLESHORTVERSION}"

    #echo -e "  VERSION    : ${VERSION}"

    ## ipa更名规则  项目名_版本_年月日_时分

    IPANAME="${TARGET_NAME}_${BUNDLESHORTVERSION}_${BUILD_DATE}.ipa"

    ## 更名后ipa路径

    EXPORTPATHNEWIPA=$EXPORTPATH/$IPANAME

    echo -e "============Export end :${BUILD_DATE}============"

    echo -e "============IPA Old Name: ${EXPORTPATHIPA}============"

    echo -e "============IPA New Name: ${EXPORTPATHNEWIPA}============"

    ## IPA更名

    cp $EXPORTPATHIPA $EXPORTPATHNEWIPA

    echo -e "============Create New Name Success============"

    ## 删除老IPA

    rm $EXPORTPATHIPA

    #echo -e "============Delete Old Name Success============"

    *******************以下内容根据需要而加***************************

    #测试代码

    #读取配置信

    ## info.plist路径

    #PROJECT_INFOPLIST_PATH="${ARCHIVEPATH}/Info.plist"

    #BUNDLEIDENTIFIER=$(/usr/libexec/PlistBuddy -c "print :ApplicationProperties:CFBundleIdentifier" "${PROJECT_INFOPLIST_PATH}")

    #BUNDLESHORTVERSION=$(/usr/libexec/PlistBuddy -c "print :ApplicationProperties:CFBundleShortVersionString" "${PROJECT_INFOPLIST_PATH}")

    #DISPLAYNAME=$(/usr/libexec/PlistBuddy -c "print Name" "${PROJECT_INFOPLIST_PATH}")

    #修改plist配置文件

    #/usr/libexec/PlistBuddy -c 'Set items:0:metadata:bundle-identifier '"${BUNDLEIDENTIFIER}"'' ${WORKSPACE}/${ProjectName}.plist

    #/usr/libexec/PlistBuddy -c 'Set items:0:metadata:bundle-version '"${BUNDLESHORTVERSION}"'' ${WORKSPACE}/${ProjectName}.plist

    #/usr/libexec/PlistBuddy -c 'Set items:0:metadata:title '"${DISPLAYNAME}"'' ${WORKSPACE}/${ProjectName}.plist

    #将动态修改好的plist copy到build下(添加到jobs下,免得删除)

    #cp ${WORKSPACE}/${ProjectName}.plist build/${ProjectName}.plist

    相关文章

      网友评论

          本文标题:Jenkins iOS搭建(无需安装Keychains插件)

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