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