<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Noey Jariya on Medium]]></title>
        <description><![CDATA[Stories by Noey Jariya on Medium]]></description>
        <link>https://medium.com/@n.jariya?source=rss-ec06653aa5d8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PXCBPysVzE2uE9xtPvI6rg.jpeg</url>
            <title>Stories by Noey Jariya on Medium</title>
            <link>https://medium.com/@n.jariya?source=rss-ec06653aa5d8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 03:41:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@n.jariya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ทำ CI/CD ใน Android ด้วย Gitlab CI]]></title>
            <link>https://medium.com/dev-it/%E0%B8%97%E0%B8%B3-ci-cd-%E0%B9%83%E0%B8%99-android-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-gitlab-ci-fac2d4d3ae49?source=rss-ec06653aa5d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fac2d4d3ae49</guid>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Noey Jariya]]></dc:creator>
            <pubDate>Wed, 21 Feb 2018 11:07:16 GMT</pubDate>
            <atom:updated>2018-02-21T11:07:16.725Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pPtWN9zylb9_ej3uECqH9Q.png" /></figure><p>การเขียนแอปพลิเคชัน ขั้นตอนที่เราต้องทำกันอยู่เสมอคือการ Build, Test และ Deploy เบื่อมั้ยที่ต้องมานั่งกดทีละขั้นตอนทุกครั้งที่แอปมีการอัปเดต? มาใช้ CI/CD ทำเรื่องพวกนี้แทนกันดีกว่า..</p><p>ในบทความนี้จะพูดถึงว่า CI/CD คืออะไร? ทำงานร่วมกับ Android ยังไง? แล้วจะสั่งให้มัน Build และ Deploy แอพเองทุกครั้งที่เรา push code ขึ้น gitlab ต้องทำยังไง?</p><h4>เริ่มต้นกันที่ CI/CD คือ?</h4><p>CI/CD หรือ Continuous Integration/ Continuous Deployment<strong> </strong>เป็นเครื่องมือที่ช่วยให้การทำงานต่างๆทำงานเองอัตโนมัติ เช่นในกรณีนี้ เราเขียนแอพ เราอยากจะให้มัน build แล้วก็ deploy เองเลยเวลาที่แอปเรามีการอัปเดต CI ก็จะอ่าน script คำสั่งที่เราเขียนขึ้นมาและทำงานให้เองอัตโนมัติ</p><h4>Gitlab CI</h4><p>จริงๆแล้ว CI มี server ให้เลือกใช้อยู่อีกหลายตัวเช่น Jenkins, Travis-CI, Buildbot, Drone และอีกมากมาย แต่เหตุผลที่เลือก Gitlab CI เนื่องจากใช้ Gitlab เป็น version control อยู่แล้ว เลยเลือกใช้ CI ของ Gitlab ซะเลย :)</p><h4>Flow การทำงาน</h4><p>ในบทความนี้จะขอข้ามขั้นตอนการทำ Test ไป จะใช้ CI เพื่อทำเพียง automate build และ deploy app เท่านั้น โดยมี Flow การทำงานเบื้องต้นดังรูปภาพด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7Hgc0Ae7EkmLFfvRcpV8A.png" /></figure><p>Gitlab CI จะทำงานโดยการอ่าน script หรือคำสั่งจาก ไฟล์ .gitlab-ci.yml ซึ่งเราจะสร้างไฟล์นี้ไว้ที่โฟลเดอร์ของโปรเจ็ค</p><h4>ไฟล์ .gitlab-ci.yml</h4><p>ไฟล์นี้เป็นไฟล์สำคัญ สำหรับการทำ CI ด้วย Gitlab เพราะ Gitlab CI จะเริ่มต้นทำงานโดยอ่านคำสั่งผ่านไฟล์นี้ ซึ่ง Gitlab จะอ่านและทำงานตามคำสั่งในไฟล์นี้เองโดยที่เราไม่ต้องใส่คำสั่งใดๆเพิ่ม แค่ใส่ไฟล์นี้เอาไว้ที่โฟลเดอร์ของโปรเจ็คเท่านั้น</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5c02765491ad5337ecce150af5e5fe4/href">https://medium.com/media/e5c02765491ad5337ecce150af5e5fe4/href</a></iframe><p><strong>ขั้นตอนหลักๆ จากไฟล์ .gitlab-ci.yml ข้างต้น ประกอบด้วย</strong></p><ul><li>Define image</li><li>Define variables</li><li>Prepare environment</li><li>Define stages</li><li>Build app</li><li>Deploy app</li></ul><p><strong>ทำความเข้าใจ(บาง)ขั้นตอนในไฟล์ .gitlab-ci.yml</strong></p><p><strong>Define image</strong></p><pre>image: openjdk:8-jdk</pre><p>เรา define image เพื่อเป็นการบอก docker ว่าจะใช้ docker image ตัวไหนในการทำงานครั้งนี้</p><p><strong>Define stages</strong></p><pre>stages:<br>  - build<br>  - deploy</pre><p>stages แต่ละ stages เปรียบเหมือนการจัดกลุ่มให้แต่ละ jobs ซึ่ง jobs ใน stage เดียวกันจะทำงานเป็น parallel โดยแต่ละ jobs ใน stages นั่นๆต้องทำงานเสร็จก่อน stages ถัดไปจะเริ่มทำงาน</p><p><strong>Build App + Deploy App</strong></p><p>ก่อนจะไปลงรายละเอียดขั้นตอนในการ build กับการ deploy ด้านล่างคือ flow การทำงานของทั้งสองขั้นตอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*CXSAad92L1df3qWvzeTY2w.png" /></figure><p><strong>Build App</strong></p><pre>build:<br>  stage: build<br>  script:<br>#  Creating variable<br>    - export APP_VERSION=V.${CI_BUILD_TAG}<br>    - export FILE_NAME=app-$APP_VERSION.apk<br>    <br>#  Build apk<br>    - ./gradlew assembleRelease<br>    <br>#  Change file name<br>    - mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/$FILE_NAME<br>  artifacts:<br>    paths:<br>    - app/build/outputs/<br>  only:<br>    - tags</pre><p>build job เริ่มต้นด้วยการสร้างตัวแปรเพื่อมาเก็บเลข version ซึ่งเอาค่ามากจากชื่อ tags ตอนเรา push ซึ่งคือ ${CI_BUILD_TAG} &gt; คำสั่ง assembleRelease คือให้ build release version ของ app &gt; เปลี่ยนชื่อไฟล์เป็นเลข version &gt; output ที่ได้จากการ build จะสามารถดาวน์โหลดได้ผ่าน artifacts field ตาม path ที่กำหนดเอาไว้ โดย job นี้จะทำงานก็เมื่อเรา push tags ใน Gitlab เท่านั้น</p><p><strong>Deploy App</strong></p><pre>deploy:<br>  stage: deploy<br>  script:<br>#  Installing node and firebase<br>    - curl -sL <a href="https://deb.nodesource.com/setup_9.x">https://deb.nodesource.com/setup_9.x</a> | bash<br>    - apt-get install -y nodejs<br>    - npm install -g --unsafe firebase-tools<br>    - firebase init database<br>    - firebase use --token $FIREBASE_DEPLOY_KEY production</pre><pre>    - export APP_VERSION=V.${CI_BUILD_TAG}<br>    - export FILE_NAME=app-$APP_VERSION.apk<br>    - echo $FILE_NAME</pre><pre>#  Uploading apk to S3<br>    - ./gradlew uploadApk<br>    <br>#  Updating value on firebase realtime database<br>    - echo &quot;\&quot;$APK_LINK/production/release/$FILE_NAME\&quot;&quot; | firebase database:set /config/app/test/stable/url --confirm    <br>    - echo &quot;\&quot;$APP_VERSION\&quot;&quot; | firebase database:set /config/app/test/stable/version --confirm<br>  dependencies:<br>    - build<br>  only:<br>    - tags</pre><p>ใน stage deploy นี้ขึ้นอยู่กับแต่ละคนว่าจะเอา output ของ การ build ไปทำอะไร เช่นอัพโหลดขึ้น Google Play เป็นต้น แต่สำหรับในบทความนี้ ตาม code ข้างต้น จะนำ output ที่ได้อัพโหลดขึ้น server ของ S3</p><p>จะเริ่มต้นด้วยการติดตั้ง Node และ Firebase &gt; set ค่าตัวแปร &gt; Upload APK ขึ้น S3 server(สามารถดูการเรียกใช้ plugin uploadApk ได้ที่ <a href="https://github.com/rambabusaravanan/gradle-android-s3">https://github.com/rambabusaravanan/gradle-android-s3</a> ) &gt; update Url และ version ล่าสุดของ APK ไฟล์ไว้ที่ Realtime database ของ Firebase เพื่อนำไปใช้งานต่อไป</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fac2d4d3ae49" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-it/%E0%B8%97%E0%B8%B3-ci-cd-%E0%B9%83%E0%B8%99-android-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-gitlab-ci-fac2d4d3ae49">ทำ CI/CD ใน Android ด้วย Gitlab CI</a> was originally published in <a href="https://medium.com/dev-it">True e-Logistics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>