ios jenkins
by Agam Mahajan
通过Agam Mahajan
如何使用Jenkins和Fastlane制作iOS点播构建系统 (How to make an iOS on-demand build system with Jenkins and Fastlane)
This article is about creating iOS builds through Jenkins BOT, remotely, without the need of a developer.
本文旨在通过Jenkins BOT远程创建iOS构建,而无需开发人员。
Before starting, I want to say that this is my first article. So feel free to leave a comment if something can be improved :)
在开始之前,我想说这是我的第一篇文章。 如果可以改进,请随时发表评论:)
为什么这是个好主意? (Why is this a good idea?)
When a developer makes a feature, they QA test it before pushing it to production. So a build has to be shared with the QA team with some test configurations.
当开发人员创建功能时,他们会先对其进行质量检查,然后再将其投入生产。 因此,必须通过一些测试配置与质量检查团队共享构建。
Xcode (the IDE) takes a significant amount of time to compile and generate this build. This means that any person that needs the build would have to install the IDE, clone the repository, create a signing identity and certificate and then create the build themselves. Or depend on the developer to create one for them.
Xcode(IDE)需要大量时间来编译和生成此版本。 这意味着需要构建的任何人都必须安装IDE,克隆存储库,创建签名身份和证书,然后自己创建构建。 或者依靠开发人员为他们创建一个。
During the build creation process, the IDE is unusable. This severely impacts the productivity of the developer. In my company, the average build time of an .ipa is around 20 mins. On average, a developer makes 2–3 builds daily.This means 5 working hours a week get wasted.
在构建创建过程中,IDE不可用。 这严重影响了显影剂的生产率。 在我的公司中,.ipa的平均构建时间约为20分钟。 平均而言,开发人员每天进行2-3次构建,这意味着每周要浪费5个工作小时。
But what if there was an automated system which could generate the builds on its own? This would free the developers from this responsibility. It would also make it possible for anyone to get a build easily.
但是,如果有一个可以自行生成构建的自动化系统呢? 这将使开发人员摆脱这种责任。 这也将使任何人都可以轻松获得构建。
Jenkins is one of the solutions to our problem.
詹金斯是解决我们问题的方法之一。
Making builds easily available to testers and developers ensures that people are able to test features faster and ship to production more easily. This improves the productivity of development teams. It also improves the quality of products pushed to production.
向测试人员和开发人员轻松提供构建版本可确保人们能够更快地测试功能并更轻松地将其交付生产。 这提高了开发团队的生产力。 它还提高了推向生产的产品的质量。
现在开始吧。 (Let’s get started now.)
先决条件 (Prerequisites)
You will require:
您将需要:
- macOS Machine (it is better to run it on Mac products) macOS机器(最好在Mac产品上运行)
- 10 GB of drive space (for Jenkins) 10 GB的驱动器空间(用于Jenkins)
Java 8 installed (either a JRE or Java Development Kit (JDK) is fine)
已安装Java 8(可以使用JRE或Java开发工具包(JDK))
Java 8 installed (either a JRE or Java Development Kit (JDK) is fine)http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
已安装Java 8(可以使用JRE或Java开发工具包(JDK)都可以) http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Additional Plugins to be installed
要安装的其他插件
- homebrew 自制
- wget get
RVM Plugin
RVM插件
RVM PluginInstallation guide
RVM插件安装指南
RVM PluginInstallation guidehttps://rvm.io/rvm/security
RVM插件安装指南 https://rvm.io/rvm/security
Make one Branch with a file in it with the name Jenkinsfile
with sample code:node {
sh ‘echo HelloWorld’
}
Let's name it jenkins-integration. Will come back to this later.
使用示例代码在其中创建一个名为Jenkinsfile
的文件的分支: node {
Jenkinsfile
sh 'echo HelloWorld'
}
其命名为jenkins-integration 。 稍后会再谈到。
- Install Xcode on your machine from the App Store 从App Store在计算机上安装Xcode
- Install Fastlane on your machine. Jenkins will internally use fastlane commands to generate builds. 在计算机上安装Fastlane。 Jenkins将在内部使用fastlane命令生成构建。
Now let’s go through it step by step.
现在,让我们逐步进行操作。
步骤1.在您的计算机上安装Jenkins (Step 1. Install Jenkins on your machine)
You can install on a MacBook or mac-mini. Mac-mini is preferred as it can be kept alive.
您可以安装在MacBook或mac-mini上。 Mac-mini是首选,因为它可以保持活动状态。
Download Jenkins -> https://jenkins.io/
下载Jenkins-&g t; https:// jenkins。 io /
Run java -jar jenkins.war --httpPort=8080 in the command line. If you’re getting an error in the terminal, try a different port (for example, 9090) as sometimes some ports are not available.
在命令行中运行java -jar jenkins.war --httpPort = 8080 。 如果终端出现错误,请尝试使用其他端口(例如9090),因为有时某些端口不可用。
Browse to http://localhost:8080 and follow the instructions to complete the installation.
浏览到http:// localhost:8080并按照说明完成安装。
Then add admin credentials and don’t forget them (as did I :P). Later you can go to Jenkins > Manage Jenkins > Manager Users and do your changes if needed.
然后添加管理员凭据,不要忘记它们(就像我:P一样)。 稍后,您可以转到Jenkins>管理Jenkins>管理员用户,并根据需要进行更改。
步骤2.创建您的第一个管道 (Step 2. Creating Your first Pipeline)
Create a new job and choose Pipeline Project.
创建一个新作业,然后选择Pipeline Project 。
To check out your project, under the section Pipeline, in Definition, choose Pipeline Script from SCM and in SCM choose Git
要检出您的项目,请在“ 管道 ”部分下的“ 定义”中,选择“ SCM中的管道脚本”,然后在SCM中选择“ Git”。
Then add your repo URL and add the credentials if its a private repo. In branches to build , add */jenkins-integration, the branch which we created earlier.
然后添加您的存储库URL,并在其为私人存储库的情况下添加凭据。 在build的分支中,添加* / jenkins-integration, 我们之前创建的分支。
Make sure Script Path is Jenkinsfile which we have created in our new branch. All the scripts will be written in this Jenkinsfile.
确保脚本路径是我们在新分支中创建的Jenkinsfile 。 所有脚本都将写入此Jenkinsfile中。
Click on Save and Jenkins will automatically scan your repo with the mentioned branch and will run the Jenkinsfile script.
单击“保存”,Jenkins将使用提到的分支自动扫描您的仓库,并将运行Jenkinsfile脚本。
Now we are ready to configure our Jenkinsfile to create builds
现在我们准备配置Jenkinsfile来创建构建
步骤3.将参数添加到作业 (Step 3. Add parameters to the Job)
User input is required for
需要用户输入
- branch 科
- environment (test or prod) 环境(测试或生产)
For that we need to configure our project to take input parameters for a job.
为此,我们需要将项目配置为接受作业的输入参数。
Go to the Configure section and check This project is parameterised.Then select add parameter and add the same accordingly.
转到“ 配置”部分,然后检查“ 此项目已参数化” 。 然后选择添加参数并相应地添加。
When you click on save, you will see a new section on left side -> Build with Parameters. This will be the user interface to make builds.
当您单击保存时,您将在左侧看到一个新部分-&g t;。 用参数生成 。 这将是进行构建的用户界面。
These params will be used in our Jenkins script.
这些参数将在我们的Jenkins脚本中使用。
步骤3.配置Jenkins脚本 (Step 3. Configure Jenkins Script)
Will create multiple steps in our Jenkinsfile, each having one responsibility, and it will create a nice UI when it is built.
将在我们的Jenkinsfile中创建多个步骤,每个步骤都有一个职责,并且在构建时会创建一个漂亮的UI。
Go to your Jenkinsfile and replace the script with the following:
转到您的Jenkinsfile并将脚本替换为以下内容:
First, check out the branch through the parameter which we added earlier. Add your repo and GitHub token.
首先,通过我们之前添加的参数检出分支。 添加您的仓库和GitHub令牌。
Now the GitHub token should not be visible to others. To do this, go to Manage Jenkins-> Configure System ->Global properties and add githubToken as an environment variable.
现在,GitHub令牌对其他人不可见。 为此,请转到Manage Jenkins- &g t;。 配置系统 ->全局属性,并添加github令牌作为环境变量。
Then invoke the script to change the environment.
然后调用脚本以更改环境。
Next, invoke fastlane to clean (remove derived data, clean, delete .dsym files etc).
接下来,调用fastlane进行清理(删除派生数据,清理,删除.dsym文件等)。
If code signing is required, do that next using ad-hoc. You can use development or app store based on your needs.
如果需要代码签名,请使用ad-hoc接下来进行。 您可以根据需要使用开发或应用商店 。
Next, create builds using the gym command in fastlane.
接下来,使用fastlane中的gym命令创建构建。
步骤4.运行作业 (Step 4. Run the Job)
Now our script is ready. Go to Jenkins and open Build with Parameters.
现在我们的脚本已经准备好了。 转到Jenkins并打开Build with Parameters。
It will start to run the script and will create a nice UI with multiple steps as mentioned in the Jenkinsfile.
如Jenkinsfile中所述,它将开始运行脚本并创建具有多个步骤的漂亮UI。
When the job is completed, go to the project Users/agammahajan/.jenkins/workspace/iOS_Build_Systemsand you will see that the .ipa has been created. Voilà!
作业完成后,转到项目Users / agammahajan / .jenkins / workspace / iOS_Build_Systems ,您将看到已创建.ipa 。 瞧!
Now you can share this build with others. You can use the Slack plugin to upload the builds to Slack if you want.
现在,您可以与其他人共享此构建。 如果需要,可以使用Slack插件将内部版本上传到Slack。
结语 (Wrapping up)
So to conclude here, we can see how easy it is to setup an automated bot which enables any person to trigger builds in just 2 steps: Give Branch->Test Environment-> Done.
因此,在这里总结一下,我们可以看到设置一个自动化的bot有多么容易,它使任何人都可以通过两个步骤触发构建:提供分支->测试环境->完成。
This has helped me and my fellow developers improve productivity and ship faster. It has also helped the QA team, so that they don’t have to depend on developers every time they need to test something. I hope it benefits you and your company also.
这帮助我和我的其他开发人员提高了生产率并加快了发货速度。 它也为质量检查团队提供了帮助,因此他们不必在每次需要测试某些东西时都依赖开发人员。 我希望它也能使您和您的公司受益。
From here, the possibilities are endless.
从这里开始,无限的可能性 。
- You can make scheduled jobs to generate nightly builds. 您可以进行计划的工作以生成夜间版本。
- Upload builds directly to the App Store. 将内部版本直接上传到App Store。
- Cache the builds, so builds with the same configuration are not generated again. 缓存构建,因此不会再次生成具有相同配置的构建。
- Distributing the IPA in house for OTA (Over the air) installation. 内部分发IPA以进行OTA(无线)安装。
- Make a CI-CD pipeline to run automated tests on every commit and make them production ready. 建立CI-CD管道以对每个提交运行自动化测试,并使其准备就绪。
翻译自: https://www.freecodecamp.org/news/how-to-make-an-ios-on-demand-build-system-with-jenkins-and-fastlane-8eb1e02c73d1/
ios jenkins