คุณสามารถตั้งค่าระบบ CI พื้นฐานเพื่อป้องกันการเปลี่ยนแปลงใหม่ที่จะทําให้บิลด์ใช้งานไม่ได้หลังจากผสานรวม คุณสามารถตั้งโปรแกรมระบบ CI ที่ล้ำสมัยมากขึ้นให้ทดสอบแอปโดยอัตโนมัติและตรวจสอบว่าแอปทำงานตามที่คาดไว้ในสภาพแวดล้อมต่างๆ เช่น ระดับ API, ขนาดหน้าจอ และแพลตฟอร์ม
รูปที่ 1 ระบบ CI จะดูแลให้ที่เก็บโค้ดทำงานได้อย่างราบรื่นโดยทำการตรวจสอบก่อนผสาน
เอกสารนี้แสดงกลยุทธ์ทั่วไปที่นักพัฒนาแอปใช้เพื่อสร้างระบบ CI ที่มีประสิทธิภาพสำหรับโปรเจ็กต์ Android หลักเกณฑ์เหล่านี้เป็นแนวทางทั่วไปที่ใช้กับโซลูชันส่วนใหญ่
ตัวอย่างทั่วไป
ระบบ CI ทั่วไปจะเป็นไปตามเวิร์กโฟลว์หรือไปป์ไลน์ ซึ่งอาจมีลักษณะดังนี้
ระบบ CI จะตรวจหาการเปลี่ยนแปลงในโค้ด โดยปกติแล้วเมื่อนักพัฒนาซอฟต์แวร์สร้างคำขอดึงข้อมูล หรือที่เรียกว่า "รายการการเปลี่ยนแปลง" หรือ "คำขอผสาน"
ปรับปรุงคุณภาพของซอฟต์แวร์: CI ช่วยปรับปรุงคุณภาพของซอฟต์แวร์ได้โดยระบุและแก้ไขปัญหาตั้งแต่เนิ่นๆ ซึ่งจะช่วยลดความผิดพลาดในรุ่นซอฟต์แวร์และปรับปรุงประสบการณ์โดยรวมของผู้ใช้
ลดความเสี่ยงที่จะมีบิลด์ที่ไม่ทำงาน: เมื่อทําให้การบิลด์เป็นแบบอัตโนมัติด้วย CI คุณจะหลีกเลี่ยงบิลด์ที่ไม่ทํางานได้ดีขึ้นด้วยการแก้ปัญหาตั้งแต่เนิ่นๆ ในกระบวนการ
เพิ่มความมั่นใจในรุ่นต่างๆ: CI ช่วยตรวจสอบว่าแต่ละรุ่นมีความเสถียรและพร้อมใช้งานจริง โดยการเรียกใช้การทดสอบอัตโนมัติ CI จะระบุปัญหาที่อาจเกิดขึ้นได้ก่อนที่จะเผยแพร่ต่อสาธารณะ
การสื่อสารและการทํางานร่วมกันที่ดีขึ้น: CI ช่วยให้นักพัฒนาแอปและสมาชิกคนอื่นๆ ในทีมทํางานร่วมกันและติดตามความคืบหน้าได้ง่ายขึ้นด้วยการจัดเตรียมพื้นที่ส่วนกลางให้นักพัฒนาแอปแชร์โค้ดและผลการทดสอบ
เพิ่มประสิทธิภาพการทำงาน: CI ช่วยเพิ่มประสิทธิภาพการทำงานของนักพัฒนาซอฟต์แวร์ได้โดยทำให้งานที่ใช้เวลานานและเกิดข้อผิดพลาดได้ง่ายเป็นระบบอัตโนมัติ
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Continuous Integration basics\n\nContinuous Integration (CI) is a software development practice where developers\nfrequently merge their code changes into a central repository, after which\nautomated builds and tests run.\n\nYou can set up a basic CI system to prevent new changes that would break the\nbuild after merging in. You can program a more advanced CI system to\nautomatically test the app and make sure it behaves as expected in different\nenvironments, such as API levels, screen sizes, and platforms.\n**Figure 1.** A CI system keeps a code repository healthy by running checks before merging.\n\nThis document demonstrates common strategies developers use to set up effective\nCI systems for Android projects. These guidelines are generic and apply to the\nmajority of solutions.\n\nTypical example\n---------------\n\nA typical CI system follows a *workflow* or *pipeline*, which might look as\nfollows:\n\n1. The CI system detects a change in the code, usually when a developer creates a pull request, also called \"change list\" or \"merge request\".\n2. It provisions and initializes a server to run the workflow.\n3. It fetches the code as well as tools such as the Android SDK or emulator images if needed.\n4. It builds the project by running a given command, for example .`/gradlew\n build`.\n5. It runs the [local tests](/training/testing/local-tests) by running a given command, for example running .`/gradlew test`.\n6. It starts emulators and runs the [instrumented tests](/training/testing/instrumented-tests).\n7. It uploads artifacts such as test results and APKs.\n\n**Figure 2.** A basic CI workflow\n\nBenefits of CI\n--------------\n\nThe advantages of CI include:\n\n- **Improved quality of software**: CI can help to improve the quality of software by identifying and fixing problems early on. This can help to reduce the number of bugs in software releases and improve the overall user experience.\n- **Reduced risk of broken builds**: When you automate your build process with CI you can better avoid broken builds by resolving issues earlier in the process.\n- **Increased confidence in releases**: CI can help to ensure that each release is stable and ready for production. By running automated tests, CI can identify any potential problems before you release them to the public.\n- **Improved communication and collaboration**: By providing a central place for developers to share code and test results, CI can help to make it easier for developers and other team members to work together and track progress.\n- **Increased productivity**: CI can help to increase developer productivity by automating tasks that would otherwise be time-consuming and error-prone.\n\nFurther reading\n---------------\n\nMore more information on how you can use constant integration to improve\ndevelopment for your app, read the following pages:\n\n- **[CI Automation](/training/testing/continuous-integration/automation)**\n\n- **[CI Features](/training/testing/continuous-integration/features)**"]]