ios-jekins

2018-03-21  本文已影响17人  不排版

第一、安装Jenkins 。
安装Jenkins在mac上我用过三种,分别是下载jenkins.pkg 安装包、把Jenkins.war包放到在Tomcat的发布目录下即webapp下、用brew install jenkins。(我是用最后一种才运行成功的)。
第一种安装遇到的坑是:从git上拉取不下代码,不论是用http的方式还是用ssh的方式都不能拉取下来。有的人说ssh连不上可能是Jenkins运行时候是一Jenkins这个用户运行,不是以root啊,登录用户运行。建议切换到Jenkins用户,生成ssh的公钥和私钥。代码如下:
su jenkins
ssh-keygen -t rsa -C "你的邮箱标识" -f ~/.ssh/jenkins
然后把你的公钥和私钥分别放到git的ssh keys 和 Jenkins
具体参考[这篇文章](http://www.jianshu.com/p/ed0edb93e234
虽然我没有用第一种安装实现从git上取代码但是认为我不能pull 下代码原因肯能是git服务器限制了我的ip了。
第二、配置git。
我是通过brew install jenkins 安装的。
brew install jenkins
下面的2.93请换成自己的版本。具体到自己对应目录找。下面的8888是设定端口号。下面的命令也可以作为每次的启动命令。比如你把电脑关闭后想重新登录Jenkins可以用它。
java -jar /usr/local/Cellar/jenkins/2.93/libexec/jenkins.war --httpPort=8888
安装后出化Jenkins可以参考这篇文章安装和建立一个项目http://www.jianshu.com/p/c7b951b9b4f2
我是以http的pull git上的代码的。如下图填写git服务器http地址:

image.png

在Username中填上你登录git的用户名。password填登录git的密码。description随便写。ID不用填。
上面的配置好后,可以保存。然后跑一下看是否成功pull git上的代码。
第三、打包发布iosx项目
我没有用xcode插件,原因是老师提示签名有问题。最后试了好多方法不行最后决定用Execute shell 。最后用shell 成功了 。
代码如下:

#scheme_name为项目名称
      scheme_name="xxxx"
#build_configuration 为Debug  or  Release
  build_configuration="Release"
#定义一个变量后面要用到
  info_plist_name="Info"
#进入项目目录
  cd /Users/jfjb/.jenkins/workspace/defense_gov
# 获取项目名称
project_name=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'`
# 获取版本号,内部版本号,bundleID
info_plist_path="$project_name/$info_plist_name.plist"
bundle_version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $info_plist_path`
bundle_build_version=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $info_plist_path`
bundle_identifier=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $info_plist_path`

# 强制删除旧的文件夹
rm -rf ./$scheme_name-IPA
# 指定输出ipa路径
export_path=./$scheme_name-IPA
# 指定输出归档文件地址
export_archive_path="$export_path/$scheme_name.xcarchive"
# 指定输出ipa地址
export_ipa_path="$export_path"
# 指定输出ipa名称 : scheme_name + bundle_version
suffix=`date +"%m%d%H%M"`
ipa_name="$scheme_name-v$bundle_version_$suffix"
version="$bundle_version.$suffix"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $version" "$info_plist_path"
#打包是用的文件
 ExportOptionsPlistPath="../shell/DevelopmentExportOptionsPlist.plist"
# 指定输出文件目录不存在则创建
if test -d "$export_path" ; then
    echo $export_path
else
    mkdir -pv $export_path
fi
    echo "************************* 开始pod *************************"
    pod install --verbose --no-repo-update
    echo "************************* pod完成 *************************"
        #clean
        xcodebuild clean -workspace $project_name.xcworkspace -scheme $scheme_name -configuration $build_configuration 
        # step 2\. Build
        xcodebuild -workspace $project_name.xcworkspace -scheme $scheme_name -sdk iphoneos -configuration $build_configuration  
        # step 3\. Archive
        xcodebuild archive -workspace $project_name.xcworkspace -scheme $scheme_name -configuration $build_configuration -archivePath $export_archive_path

xcodebuild -exportArchive -archivePath $export_archive_path -exportPath $export_ipa_path -exportOptionsPlist $ExportOptionsPlistPath

mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name.ipa
if test -f "$export_ipa_path/$ipa_name.ipa" ; then
    echo "************************* 导出 $ipa_name.ipa 包成功*************************"

    else
    echo "************************* 导出 $ipa_name.ipa 包失败 *************************"
    exit 1
fi

如果上述不是太清楚可以参考这篇文章(http://www.jianshu.com/p/ad4a9c40ae59)我就是参考这篇文章弄好的有所改动。就运行成功了。
最是是发布了。先在Jenkins系统管理->插件管理->高级里面上传fir-plugin-1.9.5.hpi文件。前提是已经下载好这个文件。
最上传fir 如下

image.png
上一篇下一篇

猜你喜欢

热点阅读