美文网首页
Mac安装Jenkins进行自动化打包构建iOS项目

Mac安装Jenkins进行自动化打包构建iOS项目

作者: JamieChen | 来源:发表于2021-03-19 11:01 被阅读0次

    环境准备:

    硬件:

    macOS系统的设备

    软件:

    1.Apple ID
    2.Xcode
    3.终端
    4.Homebrew

    第一步:

    打开电脑,
    登录Apple ID
    打开App Store 下载Xcode(网络传输速度决定消耗时长)

    第二步:

    安装 Homebrew
    【链接】镜像快速安装Homebrew教程 https://brew.idayer.com
    大陆地区目前已知可用源:https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh
    终端键入:/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
    示例:

    Last login: Fri Mar 19 10:06:38 on ttys000
    work@bogon ~ % /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
    ==> Checking for `sudo` access (which may request your password).
    

    输入Mac密码

    ==> The Xcode Command Line Tools will be installed.
    
    Press RETURN to continue or any other key to abort
    

    点击回车

    ==> Installation successful!
    
    ==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
    Read the analytics documentation (and how to opt-out) here:
      https://docs.brew.sh/Analytics
    No analytics data has been sent yet (or will be during this `install` run).
    
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    
    ==> Next steps:
    - Run `brew help` to get started
    - Further documentation: 
        https://docs.brew.sh
    work@bogon ~ % 
    

    安装成功

    第三步

    利用Home-brew安装Jenkins
    官方文档:https://www.jenkins.io/download/weekly/macos/
    终端键入:brew install jenkins(网络传输速度决定消耗时长)
    示例:

    
    

    安装成功

    第四步 启动Jenkins服务

    终端键入:brew install jenkins
    示例:

    work@bogon ~ %  brew install jenkins
    ==> Downloading https://homebrew.bintray.com/bottles/openjdk%4011-11.0.10.big_sur.bottle.tar.gz
    Already downloaded: /Users/work/Library/Caches/Homebrew/downloads/62ac32569e90f211952ee41f8585cbe2fa703accb93c73d344a7163a3872af4f--openjdk@11-11.0.10.big_sur.bottle.tar.gz
    ==> Downloading http://mirrors.jenkins.io/war/2.284/jenkins.war
    ==> Downloading from http://ftp-chi.osuosl.org/pub/jenkins/war/2.284/jenkins.war
    ######################################################################## 100.0%
    ==> Installing dependencies for jenkins: openjdk@11
    ==> Installing jenkins dependency: openjdk@11
    ==> Pouring openjdk@11-11.0.10.big_sur.bottle.tar.gz
    ==> Caveats
    For the system Java wrappers to find this JDK, symlink it with
      sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
    
    openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
    because this is an alternate version of another formula.
    
    If you need to have openjdk@11 first in your PATH, run:
      echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find openjdk@11 you may need to set:
      export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
    
    ==> Summary
    🍺  /usr/local/Cellar/openjdk@11/11.0.10: 654 files, 297.3MB
    ==> Installing jenkins
    ==> /usr/local/opt/openjdk@11/bin/jar xvf jenkins.war
    ==> Caveats
    Note: When using launchctl the port will be 8080.
    
    To have launchd start jenkins now and restart at login:
      brew services start jenkins
    Or, if you don't want/need a background service you can just run:
      jenkins
    ==> Summary
    🍺  /usr/local/Cellar/jenkins/2.284: 7 files, 71.7MB, built in 11 seconds
    ==> Caveats
    ==> openjdk@11
    For the system Java wrappers to find this JDK, symlink it with
      sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
    
    openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
    because this is an alternate version of another formula.
    
    If you need to have openjdk@11 first in your PATH, run:
      echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find openjdk@11 you may need to set:
      export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
    
    ==> jenkins
    Note: When using launchctl the port will be 8080.
    
    To have launchd start jenkins now and restart at login:
      brew services start jenkins
    Or, if you don't want/need a background service you can just run:
      jenkins
    

    第五步 配置Jenkins服务

    终端键入:brew services start jenkins
    出现错误
    示例:

    Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
    fatal: unable to access 'https://github.com/Homebrew/homebrew-services/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 
    Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-services /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services --origin=origin` exited with 128.
    Error: Failure while executing; `/usr/local/bin/brew tap homebrew/services` exited with 1.
    

    大陆地区无法访问导致的

    解决方法:

    终端键入:
    cd /usr/local/Homebrew/Library/Taps/
    mkdir homebrew
    cd homebrew
    git clone https://mirrors.ustc.edu.cn/homebrew-core.git
    出现错误示例:

    Last login: Fri Mar 19 10:37:50 on ttys000
    work@bogon ~ % cd /usr/local/Homebrew/Library/Taps/
    work@bogon Taps % mkdir homebrew
    mkdir: homebrew: File exists
    work@bogon Taps % cd homebrew
    work@bogon homebrew % git clone https://mirrors.ustc.edu.cn/homebrew-core.git
    fatal: destination path 'homebrew-core' already exists and is not an empty directory.
    
    解决方法:

    1.删除路径为/usr/local/Homebrew/Library/Taps/homebrew/homebrew-corehomebrew-core文件夹
    2.重新终端键入:git clone https://mirrors.ustc.edu.cn/homebrew-core.git
    示例:

    work@bogon homebrew % git clone https://mirrors.ustc.edu.cn/homebrew-core.git
    Cloning into 'homebrew-core'...
    remote: Enumerating objects: 8, done.
    remote: Counting objects: 100% (8/8), done.
    remote: Compressing objects: 100% (8/8), done.
    remote: Total 927958 (delta 3), reused 0 (delta 0)
    Receiving objects: 100% (927958/927958), 363.81 MiB | 10.64 MiB/s, done.
    Resolving deltas: 100% (636134/636134), done.
    work@bogon homebrew % 
    

    第六步:配置Jenkins
    使用浏览器打开:http://localhost:8080
    示例:

    AF4BBA467F9E517C4C5CA4800CEC2F07.jpg

    访达 - 前往文件夹

    44AFC29C2AF30344E9E5C2E7B82D80BF.jpg 853B1193D44F58968116A0FC137625AC.jpg

    打开initialAdminPassword文件,复制出密码,就可以填到网页上去重置密码了

    3C10521D9D589C03ED71DFE331576CD4.jpg 767E5363E8F090D8FAAEBF837F27B03B.jpg 9677EFD593EB5DF7C32D24E4C744B658.jpg E0E85F5E979B14457881C0E966533526.jpg 830C5891EB63530B324CF8A4E31F4738.jpg D8DB7CDF6E3052BA2D5510B8ECCCBB9D.jpg 40E96FDFD278CAC393C3260440A19C3C.jpg 9CE319D1182D9B7939FDCE828F6FB721.jpg 4FE720756F7D36A41AC100B6A24BD9FE.jpg

    第六步 配置Jenkins局域网访问

    说明:使用brew安装jenkins默认为配置为避免与其他安装程序产生用户权限问题,会将httpListenAddress默认设置为127.0.0.1,致使仅可以在本地用localhost:8080访问,但是本机和局域网均无法用ip访问。

    解决办法:

    1.修改路径下的plist配置
    访达 - 前往文件夹:/usr/local/opt/jenkins/homebrew.mxcl.jenkins.plist

    示例:

    41FC0337ABDA46A323954B199E830BA4.jpg
    将.plist中的httpListenAddress后的ip地址(--httpListenAddress=127.0.0.1),修改为本机IP或者--httpListenAddress=0.0.0.0即可。

    2.重新启动Jenkins
    终端键入brew services restart jenkins
    示例:

    work@bogon ~ % brew services restart jenkins
    Stopping `jenkins`... (might take a while)
    ==> Successfully stopped `jenkins` (label: homebrew.mxcl.jenkins)
    ==> Successfully started `jenkins` (label: homebrew.mxcl.jenkins)
    work@bogon ~ % 
    

    第七步 安装插件

    Git Changelog Plugin
    Xcode integration
    Build Name and Description Setter
    PostBuildScript
    Keychains and Provisioning Profiles Management

    第八步 配置Git SSH

    终端键入:
    ssh-keygen -t rsa -C "appconstruction@infinities.com.cn" -b 4096

    成功示例:

    work@bogon homebrew % ssh-keygen -t rsa -C "appconstruction@infinities.com.cn" -b 4096
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/work/.ssh/id_rsa):  
    Created directory '/Users/work/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /Users/work/.ssh/id_rsa.
    Your public key has been saved in /Users/work/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:dk8z6wU9xIMoLTlWruVZI6HvbuE98l7Mb5P7ZpU00jE appconstruction@infinities.com.cn
    The key's randomart image is:
    +---[RSA 4096]----+
    |          o      |
    |         * o o E |
    |        B * + = o|
    |       . O + = = |
    |        S = = = o|
    |       . o.o B o.|
    |         ..oo = o|
    |         .+.oo ++|
    |         ..++. =*|
    +----[SHA256]-----+
    work@bogon homebrew % cat ~/.ssh/id_rsa.pub
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDqa41fjtFDf8oRlqgS9S1pLhxN2WKcAOtSbH/5+34pplStzuNBl21dcpNgMR/nNTCwZF4mG+8BqPfKeWCjioOh3uKhOybgIA8H/5DGgOs4Oi1Zh3zqoF38wFnI+N5pA14wueIxH0J3+VlsjKgIgkV274KCDowZh7PfQwh9O5l0aohe3AXytnqFF1COGHFv9vCIuaO82X5dow4JoDzt6q4jGX1hJpQs3sA1tsdB0cU5tMbH28adJPWB9yafyxniBE5WK4fld9kRV//BSc5sBwWdUwICYHOCNObnpv1866yi2FFuETYKqMUD/2I9sKT23e88toi5NTXOFfvOX1jUQLqBhW069JkpTLDhjOOhC0KFU6R50VTBL+yizrqa98sE4JvKrXibL7ewbXhjkn+dhL8GxYZvLRq2pvYo9ZcQiKdO14OP+o57a7+4VHlauSX0qMySNqMiTG78f3z9M287UO4U2DVRQIFN0w0Ll3rKACIxEIEEKnDyW4ggISDoeq9uT2jQlrCzmNohvF4vVUAWHqbaZZnxAEv0lHQ3+7UJ1pJQB1XalBgtGMqKmyJLIUiL04KqJTjGCR/xXHjU87S+g3oXkVXwFAs+4a74b0JSIzK8jW8WiH5elPaukF70D991PriROZOoS8t49ZDnV14GNgrE8+5yZvbdjKMglTaXdla6WQ== appconstruction@infinities.com.cn
    work@bogon homebrew % 
    

    出现错误:


    38B74CB962916A6208FBBC0983AA6A58.jpg
    无法连接仓库:Command "git ls-remote -h -- git@glab.***.cn:developer_ios/***.git HEAD" returned status code 128:
    stdout: 
    stderr: Permission denied, please try again. 
    Permission denied, please try again. 
    git@glab.***.cn: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    添加全局凭据:

    6325AF17D5962A67671E2DBA0D92DE83.jpg 72646E9849D63FB7427114281D12AAAE.jpg

    将 keychains复制一份到共享目录下新建Jenkins/Library/Keychains


    B9A398448EEFA04BBE72FDC86DE8F61F.jpg

    第九步 安装 fastlane

    Fastlane是一套使用Ruby写的自动化工具集,旨在简化Android和iOS的部署过程,自动化你的工作流。它可以简化一些乏味、单调、重复的工作,像截图、代码签名以及发布App

    https://github.com/fastlane/fastlane

    1.安装xcode命令行工具
    终端键入:xcode-select --install
    如果没有安装,会弹出对话框,点击安装。如果提示
    xcode-select: error: command line tools are already installed, use "Software Update" to install updates表示已经安装

    2.安装Fastlane
    终端键入:sudo gem install fastlane -NV或是brew cask install fastlane
    我这里使用gem安装的

    安装完了执行
    终端键入:fastlane --version
    确认下是否安装完成和当前使用的版本号。

    3.初始化Fastlane
    cd到你的项目目录执行
    终端键入:fastlane init

    出现问题:

    [!] Unable to locate Xcode. Please make sure to have Xcode installed on your machine
    

    解决办法:

    打开Xcode - Preferences - Locations - Command Line Tools
    添加项
    示例:


    69A134BBC138668459A23195D3A50CB3.jpg

    相关文章

      网友评论

          本文标题:Mac安装Jenkins进行自动化打包构建iOS项目

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